Forms routing based on control lookup field

Hello,
I have a list with two content type, Items and Supplier Form.

Is it possible route to specific form based on value salected in a control lookup field and in the meantime background change even the content type value?

image

Therefore, when a user select a specific value at point 1, below "Document Type" field must appear the fields require for the particular content type.

I hope explained well my target.
Thank you.

Hello @stefano.mazzi,

You can redirect users to a specific form set depending on SharePoint field value using the code. Please find the example in the documentation here.

I'm sorry, I didn't get a question about the content type. Do you want to allow users to switch between content types?

Simply I want to give to my user a control lookup field where they can choose one value and if they select a specific value a want to redirect them to a specific form with specific fields for that selected content type.
Is it possible?
Do you have e sample code to share here?
Thank you.

@stefano.mazzi,

You can save the Lookup control to local storage and refresh the page. In the custom routing settings, retrieve value from the local storage and redirect users to a specific form set.

The code for the form:

fd.spRendered(function() {
    fd.control('Lookup1').$on('change', function(value) {
        if (value)
            localStorage.setItem('FormName', value.LookupValue);
        //refresh the page
        location.reload()
    })
});

The code for the custom routing:

if (localStorage.getItem('FormName') == 'Form Number one') {
    localStorage.removeItem('FormName');
    return '9c49268c-8d61-4069-99b3-ff394cbb07dd'
}
if (localStorage.getItem('FormName') == 'Form Number two') {
    localStorage.removeItem('FormName');
    return '9c49268c-8d61-4069-99b3-ff394fdgdfdf'
}

Hello @mnikitina
thank you for your help.
I'm trying your code but I get error probably because I don't understand it well.
My users must select from lookup field or control a value, then the selected value must be set even in the original sharepoint content type field, and this last one actions must routing my form in other one.
image
Can you help me please?

@stefano.mazzi,

Thank you for clarification, but I need more details.

Do you want to redirect users to specific content type? Why not allow users to change content type directly in the Content Type field?

Or do you need to redirect to specific content type and form set? If so, how do you define to which form set users should be redirected to?

1 Like

Dear @mnikitina ,
My list has only two content type.
I created a specific field Document Type in order to choose wich kind of document I'm loading because all have the same fields, except for only one that has a specific form set and fields. For that field I created a specific content type and I want to redirect to a different form set that will have field and roles different to the other content type.
What is the best way to achieve this?
Thank you.

@stefano.mazzi,

Thank you for the details! So you have a drop-down field, each option in which represents a specific content type and a form set. Is that correct? If so, you can use this code for the form:

    fd.field('Field1').$on('change', function(value) {
        if (value == 'Miscellaneous') {
             //save form set ID to the local storage
            localStorage.setItem('FormSetID', '9c49268c-8d61-4069-99b3-ff394cbb07dd');
            //open specific content type
            fd.field('ContentType').value= '0x01080080AF88A3052D8C42B30BEBC7050B2A96'
       }
    })

The code for the custom routing must be added for each content type:

var formSet = localStorage.getItem('FormSetID')
if (formSet) {
    localStorage.removeItem('FormSetID');
    return formSet
}

You can find the content type ID in the List Settings >> Content Type >> Page URL:


And the Forms Set Id in the bottom left of the designer:
image

Note, that the Content Type field must be added to the form. If you don't want to display it, you can hide it by adding a styling:

display: none; 

image

1 Like

Hello @mnikitina,
I saw that if I update the value of the content type field, my form route automatically to the new one, without routing code, but only with this:

fd.control('DocumentType').$on('change', function(value) {
    if (fd.control('DocumentType').value.LookupValue == 'Supplier Form') {
            console.log('Supplier Form');
            fd.field('ContentType').value = '0x01004588AAF4AACE1F49A54F0A3997686D80004B3A1483EA07824387A16E5FAD002117';
        }
        else{
            console.log('Item');
        }
    })

But "Supplier Form" form open in the Full Screen Mode instead Panel Mode.

Now, just to understand better your solution.
I have only 2 content type, Item and Supplier Form.
My form must open by default as Item and only if user select in the fd.control('DocumentType') the value Supplier Form, I must change my form with the specific fields required for the selected content type.
In order to achieve this, will be enough using my code or will be better using you solution?

This this "Supplier Form" content type ID:
0x01004588AAF4AACE1F49A54F0A3997686D80004B3A1483EA07824387A16E5FAD002117

Thank you so much!

@stefano.mazzi,

Yes, your code is enough. No need to add the code for the routing.

Yes, currently it works like so. We have a task to open the form for the selected content type in the panel too, but there is no due dates yet. If you want his feature straight away, we can offer you a paid support. Please email us at support@plumsail.com for more details.

1 Like

Thank you.

When is necessary / better to use "routing"?
What is your hint?
Thank you so much @mnikitina !

@stefano.mazzi,

When you have multiple different forms for one content type, you can conditionally route users between those forms. This is when you need the code for the Custom Routing.

Please learn more about forms sets in our documentation.

1 Like

Thank you @mnikitina !
I thought right then.
Have a nice day.