Show Sub account if Account has child account else hide the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 04:06 AM
Hi All,
I have written a script include and OnLoad client script.
OnChange it is working but the same code is not working for OnLoad.
Script Include:
var getSubProduct = Class.create();
getSubProduct.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSubAccount: function() {
var subacc = this.getParameter('sysparm_account');
gs.log('Account'+subacc);
var acc = new GlideRecord('customer_account');
acc.addEncodedQuery('account_parent=' + subacc);
acc.query();
if (acc.next()) {
gs.log("I am in");
var answer = 'Yes';
} else {
gs.log("I am out");
answer = 'No';
}
return answer;
},
type: 'getSubProduct'
});
Client Script:
function onLoad() {
// var subAccount = g_form.getValue("u_sub_account");
var account = g_form.getValue("account");
var ga = new GlideAjax('getSubProduct');
ga.addParam('sysparm_name', 'getSubAccount');
ga.addParam('sysparm_account', account);
ga.getXML(myCallBack);
function myCallBack(response) {
var cc = response.responseXML.documentElement.getAttribute('answer');
alert(cc);
if (cc == 'Yes') {
g_form.setMandatory("u_sub_account", true);
//g_form.setDisplay("u_sub_account", true);
} else {
g_form.setMandatory("u_sub_account", false);
// g_form.setDisplay("u_sub_account", false);
}
}
}
Nothing is coming in the logs
Thanks,
Samiksha

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 04:34 AM
Hi,
Are you getting the alert message from Client script callback function?
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 04:41 AM
As you have 'Account' variable on form, is that variable containing default value when the form is loaded?
Also why you have created separate onLoad client script, instead you can remove the isLoading condition from the first if of your onChange Client script.
Your onChange Client script should be like :
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
var subAccount = g_form.getValue("u_sub_account");
var account = g_form.getValue("account");
var ga = new GlideAjax('account_details');
ga.addParam('sysparm_name', 'getSubAccount');
ga.addParam('sysparm_account', account);
ga.getXML(myCallBack);
//ga.getXMLAnswer(getAccount);
function myCallBack(response) {
var cc = response.responseXML.documentElement.getAttribute('answer');
alert(cc);
if (cc == 'Yes') {
g_form.setMandatory("u_sub_account", true);
}
}
g_form.clearValue("u_sub_account");
}
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 04:46 AM
Hi @Anil Lande ,
Thank you for replying.
I pasted the function in different script include then it is working. I have given snc_internal role I guess this issue is related to ACL.
Thanks,
Samiksha