
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2023 05:23 AM
I Created a Delegate catalog Item to request Delegations and I attached one Workflow. In this work flow I used run script to create delegate record automatically.
Run Script:
var del = new GlideRecord('sys_user_delegate');
del.initialize();
del.user = current.variables.requested_for;
del.delegate = current.variables.delegate_user_name;
del.starts = current.variables.start_date;
del.ends = current.variables.end_date;
del.approvals = current.variables.approvals;
del.assignments = current.variables.assignments;
del.notifications = current.variables.all_notifications;
del.invitations = current.variables.meeting_invitations;
del.insert();
With above script new delegate record is created for requested user.
But I want script for If delegate record is already exits for requested user that can be replace or update existing record Instead of creating new record for same user with new details.
Can anyone help me on this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2023 11:51 PM
Hello Akhila,
Change the code like below.
var del = new GlideRecord('sys_user_delegate');
del.addQuery('user',current.variables.requested_for);
del.query();
if(!del.next())
{
del.initialize();
del.user = current.variables.requested_for;
del.delegate = current.variables.delegate_user_name;
del.starts = current.variables.start_date;
del.ends = current.variables.end_date;
del.approvals = current.variables.approvals;
del.assignments = current.variables.assignments;
del.notifications = current.variables.all_notifications;
del.invitations = current.variables.meeting_invitations;
del.insert();
}
else
{
del.delegate = current.variables.delegate_user_name;
del.starts = current.variables.start_date;
del.ends = current.variables.end_date;
del.approvals = current.variables.approvals;
del.assignments = current.variables.assignments;
del.notifications = current.variables.all_notifications;
del.invitations = current.variables.meeting_invitations;
del.update();
}
Please mark my answer as helpful/correct if it helps you.
Regards,
Namrata
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2023 07:17 AM
Hello Akhila,
You can update the script like below.
var del = new GlideRecord('sys_user_delegate');
del.addQuery('delegate',current.variables.requested_for);
del.query();
if(!del.next())
{
del.initialize();
del.user = current.variables.requested_for;
del.delegate = current.variables.delegate_user_name;
del.starts = current.variables.start_date;
del.ends = current.variables.end_date;
del.approvals = current.variables.approvals;
del.assignments = current.variables.assignments;
del.notifications = current.variables.all_notifications;
del.invitations = current.variables.meeting_invitations;
del.insert();
}
Please mark my answer as helpful/correct if it helps you.
Regards,
Namrata

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2023 11:21 PM
Hi Namrata Ghorpadm,
I tried with above script but that is not working
It creates new delegate record instead of updating new record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2023 11:51 PM
Hello Akhila,
Change the code like below.
var del = new GlideRecord('sys_user_delegate');
del.addQuery('user',current.variables.requested_for);
del.query();
if(!del.next())
{
del.initialize();
del.user = current.variables.requested_for;
del.delegate = current.variables.delegate_user_name;
del.starts = current.variables.start_date;
del.ends = current.variables.end_date;
del.approvals = current.variables.approvals;
del.assignments = current.variables.assignments;
del.notifications = current.variables.all_notifications;
del.invitations = current.variables.meeting_invitations;
del.insert();
}
else
{
del.delegate = current.variables.delegate_user_name;
del.starts = current.variables.start_date;
del.ends = current.variables.end_date;
del.approvals = current.variables.approvals;
del.assignments = current.variables.assignments;
del.notifications = current.variables.all_notifications;
del.invitations = current.variables.meeting_invitations;
del.update();
}
Please mark my answer as helpful/correct if it helps you.
Regards,
Namrata