How to set field(catalog variable) value on requested item using client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2021 08:18 AM
Hi All,
We have one catalog variable type (select box). available choices are yes/no
default value is empty.
we are trying for particular condition , field value should be set to "No" and read only on requested item label.
so we are using on load client script but g_form.setValue('field_name',''); is not working.
How to achieve this.
Thanks in advance,
Sayan Ghosh
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2021 12:02 AM
If based on a variable then you need to use below Script :
then use as if (g_form.getValue('variables.VariableName') == ''). Have modified and shared below for reference:
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_form.getValue('variables.VariableName') == '') { // Replace your Field Name here
g_form.setValue('variables.VariableName', 'no'); // Replace Variable Name here and also the correct value of "no" which you can get from your Select Box Variable choice backend value
g_form.setReadOnly('variables.VariableName',true); // Replace your Varibale Name here/
}
}
Else if you want to check based on a Field in RITM form then use the script which was shared before.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2021 12:12 AM
Hi,
code is not working. let me tell you scenario.
currently variable type is yes/no and default value is no. selected include none option also.
so for particular condition that variable value has to be blank or none on requested item and needs to be mandatory so that user can fill that value .
overall story is we need to change the value from "no" to blank or none and need to make mandatory on requested item based on condition.
we have onchange ui policy.
set value or clear value command isn't working.
hope you get my point.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2021 12:55 AM
Hi,
The statement which you have mentioned now is completely different to what you have mentioned in your Question above.
Write a On Load catalog client script on your catalog item and make sure that the script gets applied on Requested Item view only as shown below:
Now based on the last statement scenario, I have updated the script. Please use this and check:
function onLoad() {
//Type appropriate comment here, and begin script below
g_form.clearValue('yes_no_variable'); // Replace your variable name here
if (g_form.getValue('yes_no_variable') == '') { // Replace your variable name here
g_form.setMandatory('yes_no_variable', true); // Replace your variable name here
}
}
This works for me in my PDI. Let me know if you are facing an issue.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2021 01:19 AM
Hi ,
we are using client script on requested item table. not using catalog client script.
so the option you mentioned not available on that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2021 01:27 AM
Hi,
You can easily handle it via Catalog Client script as I mentioned above.
But you do have an option to do it with Client Script as well. Please use below script in your On load Client Script :
function onLoad() {
//Type appropriate comment here, and begin script below
g_form.clearValue('variables.VariableName'); // Replace your variable name here
if (g_form.getValue('variables.VariableName') == '') { // Replace your variable name here
g_form.setMandatory('variables.VariableName', true); // Replace your variable name here
}
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke