incident table assigned to field who name starts with david in-activate that user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2024 11:51 AM - edited 05-05-2024 11:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2024 12:30 PM
var user=new GlideRecord('sys_user');
var gr=new GlideRecord('incident');
gr.addQuery('assigned_to.name','STARTSWITH','david');
//var k=gr.addExtraField('assigned_to.active');
gr.query();
while(gr.next())
{
gs.info("Found inc: " + gr.number + " with assigned_to " + gr.assigned_to.getDisplayValue());
// gr.assigned_to.active=false;
//gr.assigned_to.locked_out=false;
// gr.assigned_to.phone='123';
//k=false;
// user.update();
user.addQuery('sys_id', gr.assigned_to.toString());
user.query();
if (user.next()) {
user.active = false;
user.update()
}
}
gs.info(gr.assigned_to.active); // here getting false but in backend form not updaing
You can't update records in referenced tables like you have. the above set user "David Loo" active to false.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2024 02:21 PM
Hi @Gillerla Rajesh ,
You cant update a record directly by dot walking you have to glide record to user table from incident table then in user table you can update the user record and add a active query so that same record will not get updated again ans again, please find the code below,
var gr = new GlideRecord('incident');
gr.addEncodedQuery('assigned_toSTARTSWITHDavid');
gr.query();
var assignTo;
while (gr.next()) {
assignTo = gr.assigned_to;
gs.print(assignTo);
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', assignTo);
user.addActiveQuery();
user.query();
if (user.next()) {
gs.print("inside if");
user.active = false;
user.phone = '123';
user.update();
}
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2024 11:37 AM
Thanks for marking my answer as helpful. If it helped you in any way please accept the solution so that it will be beneficial to the future readers with the same query.
Thanks
Swathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2024 08:08 PM
It seems like you're trying to update the active field of the assigned_to user on incident records. There are a few issues in your script that might be causing it not to work as expected:
- You're creating a new GlideRecord object user, but you're not querying or updating it anywhere in your script.
- You're adding an extra field assigned_to.active to the incident GlideRecord (gr), but you're not using it anywhere.
- You're setting gr.assigned_to.active to false, but you're not updating the incident record after this assignment.
- The gr.assigned_to.active is logged after the while loop, which might not give you the desired result since it's outside the loop.
var gr = new GlideRecord('incident');
gr.addQuery('assigned_to.name', 'STARTSWITH', 'david');
gr.query();
while (gr.next()) {
gr.assigned_to.active = false;
// Optionally update other fields here
gr.update(); // Update the incident record after setting fields
}
// Log the value of assigned_to.active after the loop
gs.info("Assigned_to Active Status: " + gr.assigned_to.active);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks