onChange client script with Script Include issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago - last edited 5 hours ago
- We have two forms, Form1 and Form2 (catalog items), which can be triggered either individually or sequentially.
- Both Form1 and Form2 are configured with similar variables that are automatically populated using onLoad and onChange client scripts.
- When Form1 is submitted, an HR Case (HRC) is created with all the catalog variables stored in the HR Case Variables section. After the HRC is created, a flow runs that associates the HRC with a parent ticket, which is created after the HRC. All variables from Form1 are visible in the variables section of the HRC.
- On loading Form2, there is logic in place (using a client script and a script include) to populate the parent ticket. At this stage, the parent ticket is already associated with the HRC and is loaded as soon as Form2 opens. I attempted to retrieve two variables from the related HRC during this process.
- The new requirement is to fetch variables from the HRC and apply them to Form2 during the onChange event of the parent ticket field.
- Currently, we only need to retrieve two variables:
- One checkbox
- One select box
I have tried multiple approaches to fetch these variables but have not been successful.
Could someone please assist with the required code or approach?
Script include was added with glideajax processor and client callable. The script include was a part of lot other functions. So i was just adding the function that was using.
For now, i am trying to get at least one value. Later i will add the second variable as well.
Client script
function onChange(newValue, isLoading) {
if (isLoading || !newValue) {
return;
}
var getHRApproval = new GlideAjax('script_include.Utils');
getHRApproval.addParam('sysparm_name', 'getHRApprovalCheckandSelect');
getHRApproval.addParam('sysparm_universal', newValue);
getHRApproval.getXML(function(answer) {
g_form.setValue('is_checkbox', answer === '1' ? '1' : '0');
});
}
Script Include function
getHRApprovalCheckandSelect: function() {
var universal = this.getParameter('sysparm_universal');
var getHRApprovalCS = new GlideRecord('sn_hr_core_case');
getHRApprovalCS.addQuery('parent', universal);
getHRApprovalCS.addQuery('u_record_producer', gs.getProperty('rp.offer_position'));
getHRApprovalCS.orderByDesc('sys_created_on');
getHRApprovalCS.query();
if (getHRApprovalCS.next() && getHRApprovalCS.variables && getHRApprovalCS.variables.is_checkbox) {
var v = getHRApprovalCS.variables.is_checkbox.toString();
if (v === 'true' || v === '1' || v === 'Yes') {
value = '1';
}
}
return value;
Thanks,
Kiran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
script include
client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi Abhishek,
I will be trying your solution.
Before to that, I just came to a realization that the variables cannot be fetch from that HR case as that HR case was created from a record producer. So the values must be saved in that record producer rather than the HR case itself. If this is the situation, then instead of fetching from the HRC, i should be fetching from the catalog item variables, right?
And we use several record producer (form1) with each having utilities for different purpose but actually lands to this form2. Variables were same for every record producer.
Is my understanding correct? If so, how can i fetch those variables?