- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 07:54 AM - edited 11-22-2024 07:57 AM
Hi all,
I need to make a field mandatory in the catalog task if a variable in RITM is set to true.
I created the following client script hoping to achieve this. However, even though I can access the glide record, I can't seem to get the variables... is there another way to retrieve the values in the "variables" fields of the Request Item (sc_req_item)?
function onLoad() {
var sd = g_form.getValue('short_description');
if (sd == "Ship hardware to remote work address") {
var ritm = g_form.getValue('request_item');
var gr = new GlideRecord("sc_req_item");
gr.addQuery('sys_id', ritm);
gr.query();
if (gr.next()) {
// alert(gr.number); <-- this is fine - it returns the RITM number
var fn = gr.variables.flag; // <-- this returns "unidentified"
if (fn == 'true') {
g_form.setMandatory('description', true);
}
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 10:03 AM
Just to clarify, variables don't exist on either the RITM or Catalog Task records, but are accessible to each via the variables object. So you only need to get a variable from an RITM record if you haven't included it on this Catalog Task. Since you need this value, an easy way to accomplish this is to make sure it's included on the Catalog Task, then hide it if you don't want it seen/messed with. Once that is done, your Client script on the sc_task table, not a Catalog Client Script in the Catalog Item, would look more like this:
function onLoad() {
var sd = g_form.getValue('short_description');
if (sd == "Ship hardware to remote work address") {
var fn = g_form.getValue('flag');
if (fn == 'true') {
g_form.setMandatory('description', true);
}
}
}
The problem with your script is that GlideRecord is not recommended or supported in a Client Script. One of the reasons is that you don't have access to anything other than the immediate fields on that table. Since the variables are fetched in an object that, stored on a different table, you can't use gr.variables... in a Client Script like you can in a server script. If you can't add the variable to this Catalog Task for whatever reason, then the Client Script will need to call a Script Include via Glide Ajax, passing in the request_item, then returning true or false based on the variable value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 08:09 AM
Hi @MWright1 ,
you can achieve this by catalog UI policy, you don't have to create client script for that.
create a catalog UI policy with applies on catalog task checked.
add your condition on the catalog conditions
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 10:03 AM
Just to clarify, variables don't exist on either the RITM or Catalog Task records, but are accessible to each via the variables object. So you only need to get a variable from an RITM record if you haven't included it on this Catalog Task. Since you need this value, an easy way to accomplish this is to make sure it's included on the Catalog Task, then hide it if you don't want it seen/messed with. Once that is done, your Client script on the sc_task table, not a Catalog Client Script in the Catalog Item, would look more like this:
function onLoad() {
var sd = g_form.getValue('short_description');
if (sd == "Ship hardware to remote work address") {
var fn = g_form.getValue('flag');
if (fn == 'true') {
g_form.setMandatory('description', true);
}
}
}
The problem with your script is that GlideRecord is not recommended or supported in a Client Script. One of the reasons is that you don't have access to anything other than the immediate fields on that table. Since the variables are fetched in an object that, stored on a different table, you can't use gr.variables... in a Client Script like you can in a server script. If you can't add the variable to this Catalog Task for whatever reason, then the Client Script will need to call a Script Include via Glide Ajax, passing in the request_item, then returning true or false based on the variable value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2024 05:32 AM
Thanks, Brad.
I end up creating a business rule to pull in the values of the variables into the task table, then onload did what you describe. It's unfortunate that we can't get to the variables through gliderecord from the catalog client script and have to pull in the variables in advanced.
Thanks,
M