How to clear session data after submit catalog item?

zulhiyatiuwi
Tera Expert

Hello... I have UI action that save session data of number, short description and description of incident that i want to add to request variables

UI Action:

var session = gs.getSession();
session.putClientData('number', current.sys_id);
session.putClientData('short_description', current.short_description);
session.putClientData('description', current.description);

url="sp?id=sc_cat_item&sys_id=f959c1fa2f5a4010151e877cf699b6a9&sysparm_category=d258b953c611227a0146101fb1be7c31";

action.setRedirectURL(url);

 

And i have catalog client script in item:

function onLoad() {
    //Type appropriate comment here, and begin script below
    if (null != g_user.getClientData('number')) {
        var num = g_user.getClientData('number');
        g_form.setValue('incidentnum', g_user.getClientData('number'));
        var sd = g_user.getClientData('short_description');
        g_form.setValue('subjek', num);
        var desc = g_user.getClientData('description');
        g_form.setValue('deskripsi', desc);
    }
}

Its work, but how can i clear data session after i click the UI Action? I need to clear data after form request is load so, when i open the same form, the data will be empty. Please help. Thank you

find_real_file.png

1 ACCEPTED SOLUTION

Michael Jones -
Giga Sage

Ok, the only way I can seem to get this to work in a Catalog Item is to do it via a GlideAjax call (basically just shifting this from client-side to server side). I made a quick script include that looks like this: 

 

name: clientData
client callable: checked. 

var clientData = Class.create();
clientData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	type: 'clientData',
	clearData: function() {
		
		var session = gs.getSession();
		session.clearClientData('number');
                session.clearClientData('short_description');
                session.clearClientData('description');
		return 'clientData Cleared';
	},
	
});



And then in a client script call:

var ga = new GlideAjax('clientData');
ga.addParam('sysparm_name', 'clearData');
ga.addParam('sysparm_id', g_form.getValue('ref_server_name'));
ga.getXML(procResponse);

function procResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//indicate the response in the console
jslog(answer);
}
I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

11 REPLIES 11

Michael Jones -
Giga Sage

 

You can use clearClientData()

So, after you set the values on form load, add lines like this to your script:

g_user.clearClientData('number');

g_user.clearClientData('short_description');

g_user.clearClientData('description');

 

If this was helpful or correct, please be kind and click appropriately! 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

Thank you for reply. But that script not working in catalog client script for me. I have tried it before but its show error message when i open catalog item "there is javascript error on your browser console" and the data still shown altough im not click ui action from incident. So i need to clear the session. Or you have other advice how to copy value from incident to catalog variables trough ui action?

Michael Jones -
Giga Sage

Hmm sorry about that. Try setting the values to null once you pull them instead. 

 

g_user.setClientData('number', null);

g_user.setClientData('short_description', null);

g_user.setClientData('description', null);

 

That seems to work in my PDI. 

 

If this was helpful or correct, please be kind and click appropriately. 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

Nope, sorry, doesn't seem to work with a catalog item. 

Works like a charm on a table form, but seems to do nothing in the catalog - not even throw an error. 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!