Custum routing question

Hello,

I struggle with custom routing at the moment.

It works fine, as long as I use boolean or string in the if-statement.

Eg:
item.test== true
or
item.test2 == 'Sem'

But when I try to use a lookup-field the routing doesnt work. I cant even save the value of the lookup-field in a variable like this:

var 1 = fd.field('LookupField1').value.LookupValue;

Do you have a hint for me?

Dear @UDRO,
You're not accessing a field in routing, the form is not loaded. You can get some values from the item itself, including a lookup ID value, like this: FieldName + Id

//check if Item already exists, will return true for Edit and Display Form
if (item) {
    // return Promise
    return item.get()
        .then(function (item) {
            //if Item's Lookup field ID value is 1
            if (item.LookupId === 1) {
                //return ID of a Form Set
                return '31fb1f41-63f3-48ff-a1c2-18b4e7f7c3e7'
            }
        });
}

Sorry, I didn't post the whole code. My routing looks like this for boolean:

if (item) {
return item.get()
.then(function (item) {
if (item.booleanfieldname === true) {
return '07d39df8-0c2f-49f7-ac0c-8244dd0701d8';
}
if (item.stringfieldname_ === 'Sem') {
return '1a09c9a6-cbae-428d-8d32-b421a653603a';
}
});
}

That all works. But as soon as I try to check the lookup-field nothing works any longer.

I tried this:

if (item.lookupfieldname.LookupId === 1)

ans I tried:

if (item.lookupfieldname.LookupValue === 'Sem')

Dear @UDRO,
Please, follow the scheme shown above - there is no item.lookupfieldname.LookupId, nor item.lookupfieldname.LookupValue

Use this:
if (item.lookupfieldnameId === 1){

1 Like

Thank you. It is working now.

Is there any documentation of possible values I can get from the item?

Dear @UDRO,
It always depends on the item, which in turn is retrieved with pnpjs. One way to check it is to add console.log(item), like so:

//check if Item already exists, will return true for Edit and Display Form
if (item) {
    // return Promise
    return item.get()
        .then(function (item) {
            console.log(item);
        });
}

Make sure to open browser's console and use setting Preserve log, so it doesn't get erased on redirection: