- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2023 12:07 PM - edited 01-10-2023 12:08 PM
Hi Experts,
I need a help on this catalog client script. Script looks ok to me, bit it is not working on portal.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(g_form.getValue('account') == 'Service Account'){
g_form.setVisible('service_account_link', true);
g_form.setReadonly('service_account_link', true);
alert('Service Account');
}
}
I want to add more conditions to the if condition like.
if((g_form.getValue('account') == 'Service Account') || (g_form.getValue('account') contains 'offshore') ||(g_form.getValue('account') startwith 'billing'))
Thanks,
Jay
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2023 09:50 PM - edited 01-10-2023 10:02 PM
Hi @jay1111 ,
You can use in built Javascript methods like startsWith() and includes().
var str = g_form.getDisplayValue("account");
if(str.startsWith("billing") || str.includes("offshore")){
alert("Service Account");
}Get display value of reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2023 12:12 PM
Can fix the readonly statement to setReadOnly. with a capital O.
Also try setDisplay instead of setVisible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2023 12:33 PM
Hi Sanjiv,
Thanks for the response.
I changed it, but no help.
Account is a reference variable on form, is that the issue.?
Thanks,
Jay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2023 12:45 PM
I would suggest using a UI policy. That would be easy to use and should work. Client script should be used, when you can't achieve it using UI policy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2023 01:28 PM
I tried using UI policy first, but it didn't met my requirement.
Because I have to use conditions equal, contains and startwith.
if((g_form.getValue('account') == 'Service Account') || (g_form.getValue('account') contains 'offshore') ||(g_form.getValue('account') startwith 'billing'))
And some of users added data on account name with upper case and lower case like offshore account, OFFSHORE standard account. In this case, I used contains condition on UI policy and it didn't work. Looks like a case sensitive.
After catalog onchange script, I need a similar kind of script onsubmit script to avoid submitting the form for above condition.
So, client script is the only option for me.
Thanks,
Jay