How to Query Reference field using script

Sudesh
Tera Contributor

In catalog item, i have variable"location" as type "Reference " to location table (cmn_location),In that variable "location" it need to Hide some locations while searching on magnifying search of that Variable specific to this catalog item .

The variable "location" is in variable set & using in multiple catalog items, i cannot use Reference qualifier in this case as the requirement is specific to one catalog item.

how can achieve this by scripting?

1 ACCEPTED SOLUTION

Mahendra RC
Mega Sage

Hello Sudesh,

You can create a new variable in your variable set for example catalog_item_id and then use the onLoad client script on your variable set to set the catalog ID in this variable:

g_form.setValue("catalog_item_id", g_form.getParameter("sys_id"));

then in your reference qualifier you can pass the catalog Item ID

javascript:new your_script_include_name().function_name(current.variables.catalog_item_id);

and in your script include then you can apply query based on the catalog item id and return the result. So in future if you receive a similar requirement for other catalog Item you can just update the query or script in your script include to return the data accordingly.

If my answer helped you in any way then please do mark it as helpful. If it answered your question then please mark it correct and helpful. 

Thanks

View solution in original post

2 REPLIES 2

Mahendra RC
Mega Sage

Hello Sudesh,

You can create a new variable in your variable set for example catalog_item_id and then use the onLoad client script on your variable set to set the catalog ID in this variable:

g_form.setValue("catalog_item_id", g_form.getParameter("sys_id"));

then in your reference qualifier you can pass the catalog Item ID

javascript:new your_script_include_name().function_name(current.variables.catalog_item_id);

and in your script include then you can apply query based on the catalog item id and return the result. So in future if you receive a similar requirement for other catalog Item you can just update the query or script in your script include to return the data accordingly.

If my answer helped you in any way then please do mark it as helpful. If it answered your question then please mark it correct and helpful. 

Thanks

Hello Sudesh,

Just wanted to check with you, if the above response answered your question. If yes, then please do close this thread/question by marking the appropriate response as correct.

Thanks