Need to call system property in UI policy client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 11:42 PM - edited 12-05-2024 11:53 PM
I have UI policy script doing some function.
In that I am checking for particular order guide using sys_id.
I need to replace that sys id with system property.
I have written script include for the same but it is not working.
SI:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 07:03 AM
Please find the full code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 07:19 AM
I won't suggest to use UI policy for this.
use onLoad client script since your script is too heavy
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 07:42 AM
try this
function onCondition() {
var url = decodeURIComponent(top.location.href); //Get the URL and decode it
var workspaceParams = url.split('sysparm_guide')[1]; //Split off the url on Extra params
var serviceportalParams = url.split('sys_id');
var wkspaceParams = url.split('sc_cat_item_guide/');
//alert(workspaceParams);
var params = workspaceParams;
var allParams = '';
var ans = '';
//The params are split on slashes '/'
if (workspaceParams != null) {
allParams = params.split('&');
//alert(allParams.length);
//Search for the parameter requested
for (var i = 0; i < allParams.length; i++) {
if (allParams[i] == sysparm_guide) {
ans = allParams[0];
return allParams[0];
}
}
}
if (serviceportalParams != null) {
allParams = serviceportalParams;
}
//alert(ans);
var finalParam = '';
if (ans != null) {
finalParam = ans.replace('=', '');
}
if (wkspaceParams != null) {
finalParam = wkspaceParams[1];
}
var ga = new GlideAjax('GetOrderguide');
ga.addParam('sysparm_name', "GetOrderguideSYSID");
ga.getXMLAnswer(function(answer) {
if (finalParam == answer)
//if(finalParam == 'sys_id')
{
g_form.setMandatory('variable_name', false);
g_form.setMandatory('variable_name', false);
g_form.setVisible('variable_name', false);
g_form.setVisible('variable_name', false);
g_form.setMandatory('ms_ham_financial_approver', false);
g_form.setMandatory('ms_unlock_approvers', false);
g_form.setVisible('ms_ham_financial_approver', false);
g_form.setVisible('ms_unlock_approvers', false);
}
});
//alert(finalParam);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2024 07:21 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 02:31 PM - edited 12-06-2024 02:32 PM
I would approach this a bit different.
I would create a reference variable with "Visible on Summaries" not-checked so it is not included in notifications and stuff, UI Policy to always hide it and with the default value so that a property is not even needed. If it is to be used in more than one place, you might make it a variable set and include as needed.
Now, because it is just a variable as any other, you can use it in UI Policy conditions and you don't need to write a single line of script.
Lite on the system, easy to maintain.