Assistance with Custom Routing Code

Hi there,

I have a custom routing code that is working fine. How do I modify the code to include a second condition to route to another form based on a different people picker field. Below is the code. I have another people picker field called 'HiringManager'. I want to add an extension to this code that basically says, if they are in the 'HiringManager' column route it to a different form ID of a form set. Is this possible in one set of code?

i.e. Check if they belong to the 'HiringManager' picker field --> route to a Form ID (A)
if not check if they belong to the 'People' picker field --> route to a Form ID (B)

Code below:

//check if Item already exists, will return true for Edit and Display Form
if (item) {
    //first, get the current user
    var user;
    // return Promise
    return web.currentUser.get()
        .then(function(u) {
            user = u;
            return item.get();
        })
        .then(function(item) {
            //if field People contains current user's ID
            if(item.PeopleId && item.PeopleId.indexOf(user.Id) >= 0){
                //return ID of a Form Set
                return '2a936286-fdac-4788-80fe-d73f3b173fef';
            }
        });
}

Hello @mhannaway,

You can add one more condition to check if the user is mention in Hiring Manager field. If Hiring Manager field is a single choice Person or Group field, you can use this code:

//check if Item already exists, will return true for Edit and Display Form
if (item) {
    //first, get the current user
    var user;
    // return Promise
    return web.currentUser.get()
        .then(function(u) {
            user = u;
            return item.get();
        })
        .then(function(item) {
            //compare User ID to ID of the user in the Hiring Manager field
            if (user.Id === item.HiringManagerId) {
                //return ID of a Form Set
                return '31fb1f41-63f3-48ff-a1c2-18b4e7f7c3e7';
            }
            //if field People contains current user's ID
            else if(item.PeopleId && item.PeopleId.indexOf(user.Id) >= 0){
                //return ID of a Form Set
                return '2a936286-fdac-4788-80fe-d73f3b173fef';
            }
        });
}
1 Like

Thank you this worked perfectly :heart_eyes:

1 Like