Update field value using UI action script, when user click Close Task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2024 08:39 AM
Hello,
I have a field called "software_renew_reference" which pulls the software name from alm_license table and users have to select one software. When the fulfiller type in a new start date "new_start" in the sc task, and click the close task UI button, the start date "start_date" field of the software need to get updated with the new start date.
I tired the following script in the Ui action script , but no result yet.
Any help, idea will be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2024 09:01 AM
Hi @Zaman Sm ,
After taking a look at your code, I've done some slight modification in it. Try the below code:
(function executeRule(current, previous /*null when async*/) {
var newStartDate = current.new_start;
var selectedSoftware = current.software_renew_reference;
// Check if newStartDate is empty
if (!newStartDate) {
gs.addInfoMessage('No new start date provided. No changes made.');
return;
}
// Ensure selected software is provided before proceeding
if (selectedSoftware) {
// Query the alm_license table
var licenseGr = new GlideRecord('alm_license');
licenseGr.addQuery('sys_id', selectedSoftware); // Assuming 'software_renew_reference' holds sys_id of the alm_license record
licenseGr.query();
if (licenseGr.next()) {
// Update the start date field in the alm_license table
licenseGr.setValue('start_date', newStartDate);
var updateResult = licenseGr.update();
if (updateResult) {
gs.addInfoMessage('License start date updated successfully.');
} else {
gs.addErrorMessage('Failed to update the license start date.');
}
} else {
gs.addErrorMessage('No matching software record found in the license table.');
}
} else {
gs.addErrorMessage('Selected software is not specified.');
}
// Close the current task
current.state = 3;
current.update();
})(current, previous);
Thanks,
Hope this helps.
If my response proves helpful please mark it helpful and accept it as solution to close this thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2024 09:08 AM - edited ‎06-18-2024 11:07 AM
I really appreciate you for taking time. I tried the modified code, and I am receiving this