Script for auto assignment of approval

d4rk_sp1d3r
Giga Contributor

I don't have scripting knowledge in ServiceNow but I need to create a script for approvals that will allow to send approvals in a round robin style to a set of users for a specific group. The logic that I have for this script is below:

1. declare a variable to store the last approver
2. if last approver is equals to Alice then last approver is now BOB
3. if last approver is equals to BOB then last approver is now Charles
4. else approver is Alice

I found an existing script in our instance that is being used like this and it uses sys ID's so I assume I should be using sysID.

I have the below but i am not really familiar with the syntax and I cannot get any resource from the internet on this:

 

var result = setUserAndGroup(recordGr);
users = result.users;
groups = result.groups;
var l_approver = string
/**
* This function serves to return a list of approver users and groups.
* The Vulnerable Item record provided in the change approval request is added as the input parameter to this script.
* The function should return an object containing comma separated sys_ids for users and groups with role sn_vul.exception_approver.
*/
function setUserAndGroup(recordGr) {
// Add any logic here to construct your script as necessary.

if (lappr = 'alice') {
    return {
               users: "c82c16d91bf4b85085e055352a4bcb4f", //bob
               groups: "",

               lappr_approver = "bob"
              };
} else if (lappr == bob) {
    return {
              users: "b3e561db1bfea050d63e74c51a4bcbe8", //charlie
              groups: "",
             lappr_approver = "charlie"
              };
} else {
   return
              users: "1bc188afdc6301005d7bc76a9100b9e9", //alice
              groups: "",
              lappr = "alice"
     }
}

 

I appreciate if you can help me with this. 

3 REPLIES 3

d4rk_sp1d3r
Giga Contributor

any tip with the syntax? i can probably figure it out. Or maybe a resource where I can learn scripting.

d4rk_sp1d3r
Giga Contributor

is there a free resource where I can learn Service now Scripting? Or maybe a reference list?

Community Alums
Not applicable

Hi there,

 

Some of the useful links i would suggest are below

 

Best tutorial for servicenow javascript by @chuckm. This would be very good. All the videos from Chuck Tomasi is very good. 

 https://www.youtube.com/watch?v=62Nabpb94Jw&list=PL3rNcyAiDYK2_87aRvXEmAyD8M9DARVGK

saas with snow development tutorials

 https://www.youtube.com/watch?v=axYFU6O0b8U&list=PLzTvAeLiW8AeO2Ep-qgufgOdLJ5UoA4hf

udemy

https://www.udemy.com/course/servicenow-201-development/

Now learning Application developer course (need partner portal access )

https://nowlearning.service-now.com/lxp?id=learning_course_prev&course_id=aa1e5a5d8730fcd0ed3b74c9ce...

 

Please mark helpful/like, if the solution is inline with your expectation.

 

Regards,

Gagan k

JavaScript on the Now Platform enables you to create more complex logic and user experiences. This video series introduces you to the JavaScript language specifically tailored to its use in the Now Platform. Lab exercises in this series give you experience from basic syntax to flow control to ...