Home angularjs: extending directive then make modifications

# angularjs: extending directive then make modifications

theIronLotus
1#
theIronLotus Published in 2018-02-13 20:08:14Z
 I am working in ServiceNow and am trying to extend an ootb directive, then make some modifications to a couple functions. So far I've figured out how to extend the directive: function (spModelDirective){ return angular.extend({}, spModelDirective[0], { templateUrl:'lbl_custom_template.xml' }); }  Within this directive, there's a function called getNestedFields that I would like to make edits to: function getNestedFields(fields, containers) { if (!containers) return; for (var _container in containers) { var container = containers[_container]; if (container.columns) { for (var _col in container.columns) { var col = container.columns[_col]; for (var _field in col.fields) { var field = col.fields[_field]; if (field.type == "container" && container.caption != "") getNestedFields(fields, [field]); else if (field.type == "checkbox_container") getNestedFields(fields, field.containers); else if (field.type == "field" || container.caption=="") fields.push(formModel._fields[field.name]); } } } } }  Can someone provide some guidance on what the correct syntax for this would be? Thanks! More information Our team cloned the ootb widget-form and am trying to create a custom layout. Basically, we want each form section to be it's own tab much like the back-end form instead of one long form, which is what the ootb widget-form currently does. In the very first line of the sp-variable-layout template, it shows: 
 The ng-repeat of container in containers considers each form section as a separate container (which is perfect), BUT it also considers any splits as a separate container as well. So for example, if my form's layout looks like this: enter image description here This will create two tabs: one that has every field within the begin and end splits AND a separate tab with everything after the end split. The JSON object that is created looks like this: { "_bootstrap_cells": 6, "_count": 2, "visible": true, "columns": [{ "fields": [{ "name": "type_of_account", "type": "field" }, { "name": "routing_transit_number", "type": "field" }] }, { "fields": [{ "name": "type_of_payment", "type": "field" }, { "name": "check_digit", "type": "field" }] }], "caption": "Direct Deposit", "id": "b456b9d2137ac340177c36328144b0ef", "scope_name": "x_dnf_table" }, { "_bootstrap_cells": 12, "_count": 1, "visible": true, "columns": [{ "fields": [{ "name": "account_number", "type": "field" }, { "name": "account_title", "type": "field" }, { "name": "financial_institution_name", "type": "field" }] }], "caption": "", "id": "", "scope_name": "x_dnf_table" }  Notice the first "section" has a caption, but ServiceNow treats the split section as its own separate section with no caption at all. I want to change the spModel directive to produce only containers with captions as their own tab and if a container does NOT have a caption, to append it to the previous container that does have a caption. Thanks!
Jace
2#
Jace Reply to 2018-02-14 06:28:49Z
 I don't think you can edit this function as this is hosted as a file on Servicenow. See https://hi.service-now.com/scripts/app.$sp/directive.spModel.js then just control-f for the getNestedFields. Per this thread; https://community.servicenow.com/thread/247907#1059129 I believe spModal is just a wrapper for$uibModal. What you can do is make your own directive on sp_angular_provider.
 You need to login account before you can post.
Processed in 0.329971 second(s) , Gzip On .