Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Can we use JSUtil in scoped application..?

Ankita9
Tera Contributor

Can i use !JSUtil.nil in the script instead of (current.u_vendors == '')

Below is the UI action which is for a scoped application, if yes how? Please help with the script changes.

 

function promptForPromoteMIC() {
if (!g_form.getControl('work_notes')) {
getMessage('Cannot promote major incident candidate as "Worknotes" is not visible', function(msg) {
g_form.addErrorMessage(msg);
});
return false;
}

var dialog = new GlideModal('sn_major_inc_mgmt_mim_workbench_promote', false, 848, 350);
getMessage('Promote to Major Incident', function(msg) {
dialog.setTitle(msg);
});
ScriptLoader.getScripts('/scripts/incident/glide_modal_accessibility.js', function() {
dialog.template = glideModalTemplate;
dialog.on('bodyrendered', function(event) {
glideModalKeyDownHandler(event, dialog.getID());
});
dialog.setPreference('WORK_NOTES', g_form.getValue('work_notes'));
dialog.setPreference('BUSINESS_IMPACT', g_form.getValue('business_impact'));
dialog.setPreference("focusTrap", true);
dialog.render();
});
}

if (typeof window == 'undefined')
promoteMIC();

function promoteMIC() {
var arr = [];
var contact = "Manulife Internal";

var vList = current.u_vendors.toString();
var venList = vList.split(",");

if (venList > 0) {
arr = current.u_vendors.split(',');

} else
current.u_vendors = current.u_vendors; //(I have been advised to use !JSUtil.nil instead of (current.u_vendors == '')

var arrayUtil = new global.ArrayUtil();
if (!arrayUtil.contains(arr, contact)) {
arr.push(contact);
}
current.u_vendors = arr.join();
var mim = new sn_major_inc_mgmt.MajorIncidentTriggerRules(current);
mim.approveMIC();
action.setRedirectURL(current);
}

3 REPLIES 3

Kieran Anson
Kilo Patron

Hi,

yes JSUtil is available to non-global scopes. You'll need to prefix your call with the global namespace identifier.

global.JSUtil.nil(current.u_vendor).

Ankur Bawiskar
Tera Patron

Hi,

It should work as per what Kieran has mentioned by using the global quantifier

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankita 

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

If not, please let us know if you need some more assistance.

Thanks!
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader