Need to display the variable in catalog form

suuriyas
Tera Contributor

HI Community,

 

I have a requirement, in catalog form we have a variable called software (reference to software install table) and price variable (single line). in software install table there is field called Licence Type 

When user selects any software in software variable and its licence type is licensed then show the price variable in form if not do not show this.

Please provide me the catalog client script and script include.

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@suuriyas 

you cannot do this with UI policy.

You will have to use onChange client script with getReference callback and check the type and then show/hide the other variable

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    var ref = g_form.getReference('softwareVariable', callBackMethod); // software variable name
}

function callBackMethod(ref) {
	// compare correct field name and choice value for licensed
    if (ref.licenseTypeField == 'licensed')
        g_form.setDisplay('otherVariable', true); // give other variable name here
    else
        g_form.setDisplay('otherVariable', false); // give other variable name here
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Mark Manders
Mega Patron

It's an empty string variable that you want to show? I am not sure what the use will be, but you can easily get it there by adding a hidden (choice) variable that you let autofill on software selection (option on the variable form no need for scripting). You can then use a catalog ui policy or client script on the price field to show if that hidden field is 'licensed'.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

HI @Mark Manders ,

 

Thanks for replying

My requirement is when user select any software in software variable it needs to check the licensed type of that software if the type is licensed then price variable needs to be visible in form

suuriyas_0-1751614066132.pngsuuriyas_1-1751614125728.png

How can we achieve this without script in UI Policy i tried i think we cannot do that via policy

Ankur Bawiskar
Tera Patron
Tera Patron

@suuriyas 

you cannot do this with UI policy.

You will have to use onChange client script with getReference callback and check the type and then show/hide the other variable

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    var ref = g_form.getReference('softwareVariable', callBackMethod); // software variable name
}

function callBackMethod(ref) {
	// compare correct field name and choice value for licensed
    if (ref.licenseTypeField == 'licensed')
        g_form.setDisplay('otherVariable', true); // give other variable name here
    else
        g_form.setDisplay('otherVariable', false); // give other variable name here
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

HI @Ankur Bawiskar ,

 

Thanks for the reply

 

Yes it works but not sure why im getting the console error

suuriyas_0-1751621770563.png