Getting empty variables in RITM form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 10:46 PM
Hello All,
I have created a variable set and few variables in that. Variables are like Requested for, Manager, Location, Department and Company. As you can see , these all are reference type variables. I have created a Script Include and Catalog Client Script to populate these variables based on Requested For selected. Now my script include and client script is working fine and all the values are getting populated, but when I click on Order Now and go to RITM record, except for Requested For variable, none of the variables are getting populated. Because of this, I am not able to create manager's approval through workflow as there is no value in Manager Variable in RITM record.
I have seen some community posts which says variable set's name and variable's name should not be same. And I already have different names for both.
I am attaching an image Of RITM record for reference.
Thanks in advance,
Ishita Shrivastava.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 12:10 AM
Hi,
Is this happening for all users or only for particular user?
Also please deactivate the client script which is working on change of Requested For
Try to populate the values manually and check if they still exists after submitting Request on RITM
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 12:25 AM
Hi Ankur,
Yes, it is happening for all users. I tried what you suggested, and while entering values manually, they are getting populated in the RITM form. Can it be problem with my Script Include and Client Script? I am pasting the Script Include and Client Script for your reference.
Client Script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var requested_for = newValue;
var ga = new GlideAjax('PopulateValues');
ga.addParam('sysparm_name','getValues');
ga.addParam('sysparm_user',requested_for);
ga.getXML(callback);
function callback(response)
{
var ans = response.responseXML.documentElement.getAttribute('answer');
var set = JSON.parse(ans);
g_form.setValue('manager',set.Manager);
g_form.setValue('company',set.Company);
g_form.setValue('department',set.Department);
g_form.setValue('office_location',set.Location);
}
//Type appropriate comment here, and begin script below
}
Script Include :
var PopulateValues = Class.create();
PopulateValues.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getValues : function(){
var user = this.getParameter('sysparm_user');
var gr = new GlideRecord('sys_user');
gr.addQuery('user',user);
gr.query();
var obj =
{
Manager : " ",
Company : " ",
Department : " ",
Location : " "
};
while(gr.next())
{
obj.Manager = gr.manager.name.toString();
obj.Company = gr.company.name.toString();
obj.Department = gr.department.name.toString();
obj.Location = gr.location.name.toString();
return JSON.stringify(obj);
}
},
type: 'PopulateValues'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 01:00 AM
Hi Ishita,
Some error in your script;
requested_for variable -> it is reference to sys_user table but in script include you are querying with incorrect column
It should be sys_id and not user
Also no need of while use if since there will be 1 user with that sys_id in table
updated code below
Ensure: "Applies on Requested Items" checkbox is Unchecked
"Applies on Target Record" checkbox is Unchecked
var PopulateValues = Class.create();
PopulateValues.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getValues : function(){
var user = this.getParameter('sysparm_user');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',user);
gr.query();
var obj =
{
Manager : " ",
Company : " ",
Department : " ",
Location : " "
};
if(gr.next())
{
obj.Manager = gr.manager.name.toString();
obj.Company = gr.company.name.toString();
obj.Department = gr.department.name.toString();
obj.Location = gr.location.name.toString();
return JSON.stringify(obj);
}
},
type: 'PopulateValues'
});
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 11:54 PM
Hi Ankur, I made the changes that you suggested, but I am still getting empty values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2022 07:21 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader