The CreatorCon Call for Content is officially open! Get started here.

Scripting Help- Issue with Auto Populated Variables in a Catalog Item from a UI Action

Su522
Kilo Sage

I have a UI Action and an onLoad Catalog Client Script that auto-populates a variable from a record to the Catalog Item form.

This works perfect. 

However, if I manually open the Catalog Item on the Portal, the variable is auto- populated with the previous variable from using the UI Action.

How can I prevent this?

When manually ordering the Catalog Item, the variable should be blank when opening the Catalog Item form.

 

Here is my code.

UI Action:

var session = gs.getSession();
session.putClientData('short_desc', current.short_description);
var short_desc = current.short_description;
gs.setRedirect('com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=ea3841fc4751351010057cb2a36d438b&sysparm_short_desc=' + short_desc);

 

Catalog Client Script:

function onLoad() {
var sd = g_user.getClientData('short_desc');  
g_form.setValue('short_desc', sd);    
}

 

Help is Greatly appreciated!!

Thank you.

1 ACCEPTED SOLUTION

In that case, the simplest solution may be to use your original UI Action and Catalog Client Script, but change the UI Type on the CCS to 'Desktop' so that it doesn't run in Service Portal. 

View solution in original post

9 REPLIES 9

Brad Bowman
Kilo Patron
Kilo Patron

You shouldn't need the Catalog Client Script if you don't want to populate the variable when initiating the item manually, since the UI Action has the sysparm to set the value when that is used.

@Brad Bowman  

My UI Action code does not populate the variable in the Catalog Item. 

When I click the UI Action- it takes me to the Catalog Item, in the same window, and the Description field is blank. 

Could you help me script it to where it does populate the Catalog Item variable from just the UI Action?

 

Here is my code.

UI Action:

var session = gs.getSession();
session.putClientData('short_desc', current.short_description);
var short_desc = current.short_description;
gs.setRedirect('com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=ea3841fc4751351010057cb2a36d438b&sysparm_short_desc=' + short_desc);
 
 
I appreciate your help!
Thank you,
Susan

Sorry, I was confusing a solution we had in place.  In the UI Action we are not using getSession or putClientData, just the URL.  In the Catalog Client Script we are populating the variable from the URL - so when loading the Catalog Item directly, the sys_parm won't be there, but should still work from the UI Action

function onLoad() {
    var url = top.location.href;
    var sd = new URLSearchParams(url).get("sysparm_short_desc");
    g_form.setValue('short_desc', sd);
}

@Brad Bowman  

Hi Brad,

I appreciate your help!! But this still isn't working. Now the Short Description from the record does not populate at all when I click the UI Action (it just redirects to the Catalog Item in the same window)

 

Here is my code for the UI Action:

var session = gs.getSession();
session.putClientData('short_desc', current.short_description);
var short_desc = current.short_description;
gs.setRedirect('com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=ea3841fc4751351010057cb2a36d438b&sysparm_short_desc=' + short_desc);
 
Here is my code for the Catalog Client Script:
function onLoad() {
    var url = top.location.href;
    var sd = new URLSearchParams(url).get("sysparm_short_desc");
    g_form.setValue('short_desc', sd);
}
 
Can you please help?
I really appreciate you!!
Thank you,
Susan