ATF: Set field values using a Server side script to a catalog item.

Ijaazops
Kilo Expert

I am trying to set field to a catalog item using a server side script.

Catalog name: Onboarding. 

i am trying to set the fields "Type of facility access" and "Type of it cluster" which is dependent on the "on boarding location".

PS: I am new to scripting.

 

3 REPLIES 3

Jace Benson
Mega Sage

Can you include what you've tried specifically. 

Trent - CloudPi
Kilo Contributor

Is there any particular reason you need to use a server side script for this? I would recommend using a Client side onChange rule.

 

Assuming you can use a Client side script:

 

First you would want to set the Field Name to the "On-boarding Location" field. 

For the Type field, select onChange.

(Note: If the end user will be filling this form in the Portal view, be sure to allow that with the UI Type Field)

 

Try using this script and substituting the words within the brackets "[]", with the back end value for the text within. Make sure to include the quotes and remove the brackets as well in the script field.

 

if(newValue == '[On-boarding Location 1]'){

g_form.setValue('[Type of facility access variable name]' , '[desired variable choice]')

g_form.setValue('[Type of IT cluster]' , '[value]')

}

 

else if(newValue == '[On-boarding Location 2]'){

g_form.setValue('[Type of facility access variable name]' , '[desired variable choice]')

g_form.setValue('[Type of IT cluster]' , '[value]')

}

 

else if(newValue == '[On-boarding Location 2]'){

g_form.setValue('[Type of facility access variable name]' , '[desired variable choice]')

g_form.setValue('[Type of IT cluster]' , '[value]')

}

 

//in the case where 2 On-boarding locations set the same values you would write the if statement like this:

 

else if(newValue == '[On-boarding Location 3]' ||newValue == '[On-boarding Location 4]' ){

g_form.setValue('[Type of facility access variable name]' , '[desired variable choice]')

g_form.setValue('[Type of IT cluster]' , '[value]')

}

 

***End of Code***

You can repeat this as may times as needed depending on how many choices are in the On-boarding Location field.

As the Type of IT cluster field is read-only, I'm unsure what value it needs to hold. In most cases, it would be the back end value for the choice associated with that variable. However, if it is a reference field it would need a sys_id.

 

Note: Please mark reply as correct / helpful if it answers your question.

Let me know if you need anything else!

Trent 

 

Hi Trent,
 
Thank you for the effort above.
I am specifically using a server side script because i am unable to set the  "Type of facility access" and "Type of IT cluster"
through the ATF, since they are loaded through a onChange client script.
Could you please help me how i can query the catalog item before it is saved to the "Requested Item" table.
 
Thanks
Ijaazops