Need to call system property in UI policy client script

Aswin Chandras1
Tera Contributor

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:

var GetOrderguide = Class.create();
GetOrderguide.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getProperty: function() {
        return gs.getProperty('name of property');
    },

    type: 'GetOrderguide'
});
 
UI policy script:
var ga = new GlideAjax('x_mosti_ms_hardwar.GetOrderguide');
ga.addParam('sysparm_name', "getProperty");
ga.getXML(myCallBack);
function myCallBack(response) {
var prop = response.responseXML.documentElement.getAttribute('answer');

}
 
With the prop I need to call in the below condition
 
if(finalParam == 'sys_id')// calling order guide sysy_id here
{
    g_form.setMandatory('variable_name',false);
g_form.setMandatory('variable_name',false);
g_form.setVisible('variable_name',false);
g_form.setVisible('variable_name',false);
 
}
 
 
9 REPLIES 9

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hello @Aswin Chandras1 

 

Can you add log statements (alert in the client script) to know which value it is returning?

In the if condition you are checking with finalParam where it is defined?

It should be against the returned value right?

Brad Bowman
Kilo Patron
Kilo Patron

You should start troubleshooting by alerting/logging 'prop' to see if you are getting the expected response.  You are not using 'prop' in the rest of the script, which should also be enclosed in the myCallBack function, and finalParam is not defined.  If this is a partial script, that's not as helpful for troubleshooting purposes.  This script may not even be running as the conditions/trigger on scripted UI Policies can be tricky.  If you find this to be the case, use an onLoad and/or onChange Catalog Client Script Instead.

Hi Brad,
This is my whole script.

 

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(answer != ''){
    alert(answer);
}
});

//alert(finalParam);
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);
}
}

Ankur Bawiskar
Tera Patron
Tera Patron

@Aswin Chandras1 

your script is not correct. it seems you pasted only partial script

both UI policy and script include are in same scope?

Since you want to run it via script, Don't give any condition to your UI policy

Have you ensured Run scripts checkbox is marked as True so that the script runs.

Please add the script in "Execute if true" section

AnkurBawiskar_0-1733483798435.png

 

If yes then are you sure client callable is checked on script include.

Did you try adding gs.info() in your script include function?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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