- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 11:17 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 11:37 PM
Hi @karthik65,
If you look at the code, you're currently setting the value of a field, but you're not actually updating the record in the database.
To update a field's value in the database:
If you're working with the current record, you should use current.update().
If you're using a GlideRecord variable (in your case, the variable is task), you need to update the record with task.update().
Example:
After setting the value of a field using task.setValue(), you must call task.update() to save the changes to the database.
task.setValue('field_name', 'value'); // Set the value for the field
task.update(); // Update the record in the database
for your reference attaching the full Code
(function executeRule(current, previous /*null when async*/) {
var task = new GlideRecord('dmn_demand_task');
task.addQuery("parent", "878babf793245210a25172918bba10fc"); // Add your query
task.query();
while (task.next()) {
gs.addInfoMessage(current.getValue('number') + " " + task.number);
task.setValue('state', 3);
task.update();
gs.addInfoMessage("Project created successfully. All associated Demand Tasks are closed.");
}
})(current, previous);
Please Mark it as Helpful and Accept the Solution , If the Solution is Resolved.
Thanks Regards ,
Badrinarayan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 11:26 PM
Hi @karthik65 ,
What type of BR is this ?.
or can you update script like below
var task = new GlideRecord('dmn_demand_task');
task.addQuery('parent', current.sys_id); // Adjust the query as per your needs
task.query();
while (task.next()) {
gs.addInfoMessage(current.getValue('number') + ' - Task: ' + task.number);
task.setValue('state', 3); // Set the state to '3' (closed)
task.update(); // Save the changes to the database
gs.addInfoMessage("Project created successfully. Demand Task " + task.number + " is closed.");
}
Please mark helpful & correct answer if it's really worthy for you.
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 11:31 PM
I missed it. Update operation thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 11:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 11:37 PM
Hi @karthik65,
If you look at the code, you're currently setting the value of a field, but you're not actually updating the record in the database.
To update a field's value in the database:
If you're working with the current record, you should use current.update().
If you're using a GlideRecord variable (in your case, the variable is task), you need to update the record with task.update().
Example:
After setting the value of a field using task.setValue(), you must call task.update() to save the changes to the database.
task.setValue('field_name', 'value'); // Set the value for the field
task.update(); // Update the record in the database
for your reference attaching the full Code
(function executeRule(current, previous /*null when async*/) {
var task = new GlideRecord('dmn_demand_task');
task.addQuery("parent", "878babf793245210a25172918bba10fc"); // Add your query
task.query();
while (task.next()) {
gs.addInfoMessage(current.getValue('number') + " " + task.number);
task.setValue('state', 3);
task.update();
gs.addInfoMessage("Project created successfully. All associated Demand Tasks are closed.");
}
})(current, previous);
Please Mark it as Helpful and Accept the Solution , If the Solution is Resolved.
Thanks Regards ,
Badrinarayan