- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2015 05:36 AM
Hello,
I have read a few discussions about this on the community, but none of the scripts seem to work for us. I would really appreciate some help with this if possible.
We have a new staff onboarding/offboarding application that creates a record for the entire employee life cycle of a new member of staff. The onboarding part is generated from a Record Producer that opens a new record on the 'u_onboarding' table and progresses it eventually to a state of 'Current Staff' (state value '6'). As part of the onboarding process, the new employee has a ServiceNow account created automatically for them, and their username from the sys_user table then appears in a reference field on the record (u_user_id). There is also a related list on the sys_user table showing the parent onboarding record.
At this point the record remains unchanged until the staff member is offboarded. The problem we have is with the offboarding record producer. This is a separate form that includes just a reference field (sys_user). There is a reference qualifier to limit this to the current line manager's team members only. On submit, the record producer should find the onboarding form with the selected username corresponding to the u_user_id field, and simply update the state field to '7' (Offboarding). This will then kick off the rest of the process.
However, this does not work at the moment. All it does is open a new blank u_onboarding record, and the target record is not updated. Obviously there is an error in our script, and we have tried a number of variations to no avail.
Script below:
//check to see if a record already exists for the user in the u_onboarding table | |
var oofb = producer.nameofemp; //nameofemp is the name of the sys_user variable | |
var rec = new GlideRecord('u_onboarding'); | |
rec.addQuery('u_user_id', oofb); | |
rec.query(); | |
//if we find a record update it | |
if (rec.next()) { | |
rec.current.state = '7'; | |
rec.update(); | |
current.setAbortAction(true); |
} |
Any help offered would be very much appreciated.
Thanks,
Charles
Solved! Go to Solution.
- Labels:
-
Integrations
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2015 01:40 AM
The correct script is as follows:
//check to see if a record already exists for the user in the u_onboarding table |
var oofb = producer.u_user_id; //u_user_id is the name of the sys_user variable, which is mapped to the u_user_id field on the u_onboarding table
var rec = new GlideRecord('u_onboarding');
rec.addQuery('u_user_id', oofb.sys_id);
rec.query();
//if we find a record update it
if (rec.next()) {
rec.state = '7';
rec.update();
current.setAbortAction(true);
producer.redirect = 'u_onboarding.do?sys_id=' + rec.sys_id;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2015 01:40 AM
The correct script is as follows:
//check to see if a record already exists for the user in the u_onboarding table |
var oofb = producer.u_user_id; //u_user_id is the name of the sys_user variable, which is mapped to the u_user_id field on the u_onboarding table
var rec = new GlideRecord('u_onboarding');
rec.addQuery('u_user_id', oofb.sys_id);
rec.query();
//if we find a record update it
if (rec.next()) {
rec.state = '7';
rec.update();
current.setAbortAction(true);
producer.redirect = 'u_onboarding.do?sys_id=' + rec.sys_id;
}