Routing to multiple Edit/Display forms based on Category (in Help desk)

My routing JS doesn't seem to be working correctly. My scripts point to the correct form but when I open the items in the list they all display in the default form.
Here's my JS - can anyone tell me what I'm doing wrong? I really need some help.

if (item) {
// return Promise
return item.get()
.then(function (item) {
//if Item's Category is Acquired Content, redirect
if (item.Category == 'Acquired Content') {
//return ID of a Form Set
return '630039b0-2ce9-4295-ac98-77ad9bc33311'
}
});
}
if (item) {
// return Promise
return item.get()
.then(function (item) {
//if Item's Category is Certificate of Insurance, redirect
if (item.Category == 'Certificate of Insurance') {
//return ID of a Form Set
return '1ee17faa-ac04-4c68-99a5-dde080c25734'
}
});
}
if (item) {
// return Promise
return item.get()
.then(function (item) {
//if Item's Category is Commissioned Content, redirect
if (item.Category == 'Commissioned Content') {
//return ID of a Form Set
return '7fa255d0-624c-4b7b-8e10-2092108aa3bd'
}
});
}
if (item) {
// return Promise
return item.get()
.then(function (item) {
//if Item's Category is Contractor/Freelancer, redirect
if (item.Category == 'Contractor/Freelancer') {
//return ID of a Form Set
return 'b36ed965-03a7-49a6-a116-3e8e0b20a1d9'
}
});
}
if (item) {
// return Promise
return item.get()
.then(function (item) {
//if Item's Category is General Contracts, redirect
if (item.Category == 'General Contracts') {
//return ID of a Form Set
return '1fc5d8fd-2488-4a31-93c5-97cb3a179f83'
}
});
}
if (item) {
// return Promise
return item.get()
.then(function (item) {
//if Item's Category is Host/Talent, redirect
if (item.Category == 'Host/Talent') {
//return ID of a Form Set
return '486aca1b-9e23-44cb-adf9-938b2faa2d32'
}
});
}
if (item) {
// return Promise
return item.get()
.then(function (item) {
//if Item's Category is Image Clearance, redirect
if (item.Category == 'Image Clearance') {
//return ID of a Form Set
return 'ba024562-e677-4a55-9a46-7672b7a73e24'
}
});
}

Hello @jbrinson,

Please check Category field value under one function like this:

if (item) {
// return Promise
return item.get()
.then(function (item) {
//if Item's Category is Acquired Content, redirect
if (item.Category == 'Acquired Content') {
//return ID of a Form Set
return '630039b0-2ce9-4295-ac98-77ad9bc33311'
}

//if Item's Category is Certificate of Insurance, redirect
if (item.Category == 'Certificate of Insurance') {
//return ID of a Form Set
return '1ee17faa-ac04-4c68-99a5-dde080c25734'
}

//if Item's Category is Commissioned Content, redirect
if (item.Category == 'Commissioned Content') {
//return ID of a Form Set
return '7fa255d0-624c-4b7b-8e10-2092108aa3bd'
}
//other conditions
});
}

That worked! You are awesome! image

1 Like

Hello,

i have a problem with the custom routing.

I just used the code above, as it seems to be the default code for the "status-routing".

I start with a defailt form when a new item is created. And from this default form i route to 1 of 5 different forms. This for explanation.

But the routing to the other forms when display or edit will not work. Always shows up the default display or edit form.

//Default form while New entry

var formSetId = localStorage.getItem('FormSetId');
if(formSetId){
  localStorage.removeItem('FormSetId');
  return formSetId;
}



//Routing to form while display and edit

if (item) {
// return Promise
    return item.get()
        .then(function (item) {
        //if Item's Category is DM, redirect
            if (item.Category == 'DM') {
            //return ID of a Form Set
            return '40cc1042-95c5-4517-a44c-d1d685f9028a'
            }

            //if Item's Category is HuG, redirect
            if (item.Category == 'HuG') {
            //return ID of a Form Set
            return '952ff876-311b-4db4-9afb-28f97db976ec'
            }
    //other conditions
    });
}

I use the category field to route to the different forms.

The console shows:
image

Is this cousing the behavoiur?

Hello @DanielB,

Try adding the condition for the new form routing:

if(!item){
        //code for a new form routing here
        var formSetId = localStorage.getItem('FormSetId');
        if(formSetId){
          localStorage.removeItem('FormSetId');
          return formSetId;
        }
}

if (item) {
//routing for edit and display forms
// return Promise
    return item.get()
        .then(function (item) {
        //if Item's Category is DM, redirect
            if (item.Category == 'DM') {
            //return ID of a Form Set
            return '40cc1042-95c5-4517-a44c-d1d685f9028a'
            }

            //if Item's Category is HuG, redirect
            if (item.Category == 'HuG') {
            //return ID of a Form Set
            return '952ff876-311b-4db4-9afb-28f97db976ec'
            }
    //other conditions
    });
}

Hello @mnikitina ,

thanks for the response.

It is funny, because now the edit form works fine from the context menu but the display form not.

Hello @DanielB,

Do you mean you are routed to the default display form?

If so, please comment out all custom code and try out routing using the code below. Thus you should be routed to a form set for all form types.

return '40cc1042-95c5-4517-a44c-d1d685f9028a'

If it works, the issue is in the code. Check the field value and the Form Set ID.

If you are still routed to the default display form, open the list in the SharePoint designer. Select Content Type and check its forms URLs and send us a screenshot:

Now it works.

Seems like i had mixed up the old forms of the ticket with the new form.
I did a reset to all forms and created them nem from the HD Backup folder.

But thanks for the above routing condition!

1 Like