- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2024 09:09 AM
We have used a mandatory variable in the catalog item form and the user missed to fill the mandatory form and the form has been got submitted.
Now the team working on the SCTASK is not able to change the state of task since the user failed to give mandatory field.
How can i change the state of the SCTASK to pending. Can i use the background script or BR.
PLS suggest.
Thannks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2024 09:27 AM - edited 10-25-2024 09:28 AM
Give this a go, you can generate your encoded query needed from the sc_task list filter, and alter the State number to whatever you require.
// Set up the GlideRecord for the 'sc_task' table
var task = new GlideRecord('sc_task');
// Add your encoded query to filter the records you want to update
task.addEncodedQuery('addEncodedQueryhere');
// Execute the query
task.query();
// Loop through the result set
while (task.next()) {
// Update the state to '3' (close complete)
task.state = '3';
// Disable workflow for this update
task.setWorkflow(false);
// Attempt to update the record
if (task.update() == 'ERROR') {
// Log an error message if the update fails
gs.error('Error updating sc_task record: ' + task.getValue('number'));
} else {
// Log a success message if the update is successful
gs.info('Updated sc_task record: ' + task.getValue('number'));
}
}
Regards
Paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2024 09:26 AM
HI @GSeeth
Why run the script to fill that mandatory field?
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.
********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect
Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2024 09:36 AM
Hi Prashant,
If i can able to write BG script for filling that mandatory fields that would be fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2024 09:27 AM - edited 10-25-2024 09:28 AM
Give this a go, you can generate your encoded query needed from the sc_task list filter, and alter the State number to whatever you require.
// Set up the GlideRecord for the 'sc_task' table
var task = new GlideRecord('sc_task');
// Add your encoded query to filter the records you want to update
task.addEncodedQuery('addEncodedQueryhere');
// Execute the query
task.query();
// Loop through the result set
while (task.next()) {
// Update the state to '3' (close complete)
task.state = '3';
// Disable workflow for this update
task.setWorkflow(false);
// Attempt to update the record
if (task.update() == 'ERROR') {
// Log an error message if the update fails
gs.error('Error updating sc_task record: ' + task.getValue('number'));
} else {
// Log a success message if the update is successful
gs.info('Updated sc_task record: ' + task.getValue('number'));
}
}
Regards
Paul