Workflow query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2024 04:48 AM
Hi All,
I am creating an approval through run script activity in the workflow. Below is the script. It is not getting attached to the RITM record. Please assist.
var requestedFor = current.variables.requested_for; // This assumes 'requested_for' is the name of the catalog variable
var grRequestedFor = new GlideRecord('sys_user');
if (grRequestedFor.get(requestedFor)) {
var bandType = grRequestedFor.u_job_band; // Assuming 'band_type' is the field name in the user profile
}
if (bandType == 'IHG_Band 1' || bandType == 'IHG_Band 2' || bandType == 'IHG_Band 3' || bandType == 'IHG_Band 4' || bandType == 'IHG_Band 5') {
// Create an approval for the Requested For's manager
var managerSysId = grRequestedFor.manager; // Get the manager's sys_id
var approval = new GlideRecord('sysapproval_approver');
approval.initialize();
approval.approver = managerSysId; // Set the manager as the approver
approval.state = 'requested'; // Set state to requested
approval.source_table = current.getTableName(); // Link to the current request
approval.source = current.getUniqueValue(); // Link to the current request
approval.source_id = current.sys_id;
approval.insert(); // Insert the approval record
} else if (bandType == 'IHG_Band 6' || bandType == 'IHG_Band 7' || bandType == 'IHG_Band 8') {
var manager = grRequestedFor.manager;
while (manager) {
var grManager = new GlideRecord('sys_user');
if (grManager.get(manager)) {
var managerBand = grManager.u_job_band;
// If the manager's band type is within 1-5, create an approval
if (managerBand == 'IHG_Band 1' || managerBand == 'IHG_Band 2' || managerBand == 'IHG_Band 3' || managerBand == 'IHG_Band 4' || managerBand == 'IHG_Band 5') {
var approval1 = new GlideRecord('sysapproval_approver');
approval1.initialize();
approval1.approver = grManager.sys_id; // Set this manager as the approver
approval1.state = 'requested'; // Set state to requested
approval1.source_table = current.getTableName(); // Link to the current request
approval1.source = current.getUniqueValue(); // Link to the current request
approval1.source_id = current.sys_id;
approval1.insert(); // Insert the approval record
break; // Exit the loop once approval is created
}
// Move to the next manager in the hierarchy (the current manager's manager)
manager = grManager.manager;
} else {
// If no manager is found, break the loop
break;
}
}
}
Best Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2024 05:14 AM
Why not just use the approval activities?
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2024 06:27 AM - edited 10-11-2024 06:32 AM
Hi @Mark Manders ,
Yes, we can use approver activity as well. But it is the same with that activity too.
I have changed source_id to document_id in the script and it is working fine now.
Can we add a wait for condition after this to get this completed and move further? because the next approval is also getting created before the previous is complete. I have added the below script in the wait for condition, but it is not working.
// Set the variable 'answer' to true or false to indicate if the condition has been met or not.
var ap = new GlideRecord('sysapproval_approver');
ap.addQuery('state', 'requested');
ap.addQuery('sysapproval', current.sys_id);
ap.addQuery();
if (ap.next()) {
var found = 'yes';
}
if (found == 'yes') {
answer = false;
} else {
answe = true;
}
Please help.
Best Regards.