How to refresh a form and save certain data entered?

jasonjones
Giga Contributor

I'm trying to create a record producer form and would like an action that when the form is submitted, it refreshes back to itself and saves certain populated fields that we specify.  This way, if multiple requests are being submitted, certain fields are already populated.

For example:

Form is for Troubleshooting:

College: - Save information

Department: Save information

Description of issue:  Do not save information

Upon "Submit" - It creates a record, refreshes the page, populates the College and Department from the previous submission.

Any suggestions are helpful.

Thanks.
Jason

4 REPLIES 4

Prasant Kumar 1
Kilo Sage

Hi,

Map correctly the record producer variables with the fields of particular table form And check the variable type should match with field type. Ex:- String(field type) -> single line text(variable type).

 

If i was able to solve your query mark my answer correct and helpful.

Thanks & regards,

Prasant kumar sahu

Michael Jones -
Giga Sage

Here is a method that I've used for a similar requirement as an example. It uses GlideAjax to put some client data, then uses a script to check on load of the form to see if there is any matching session data and if found, sets values on the form. 

This example uses two fields, one a text field named save_text and one a reference field named reference_field. 

GlideAjax Script Include

Name: setSession

Client Callable: True

var setSession = Class.create();
setSession.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	setSessionVar: function() {
	var json = this.getParameter('sysparm_json');
	gs.getSession().putClientData('json',json);
        return "session set";	
		
	},
	type: 'setSession'
	
});

Script to execute on submit to pull values from the form and set them as a session variable named "json".

function onSubmit() {
   //Create an object
	var strObj = {};
	//Set the object to have properties that match our field names
	strObj.save_text = g_form.getValue('save_text');
	strObj.reference_field = g_form.getValue('reference_field');
	
   var setSession = new GlideAjax('setSession');
   setSession.addParam('sysparm_name', 'setSessionVar');
   setSession.addParam('sysparm_json', JSON.stringify(strObj)); //Pass the object as a JSON string
   setSession.getXML(

function (response) {
   //var answer = response.responseXML.documentElement.getAttribute("answer");
//This doesn't need to "do" anything but, to test, you could pass back a value
return;
});
   
}

Then, on load, check and see if there is a session variable and if so, set the field values

function onLoad() {
   //Check is the session variable exists
	
	if(g_user.getClientData('json')) {
                //Take the string and convert it back to an object
		var obj = JSON.parse(g_user.getClientData('json'));
                //Set the values
		g_form.setValue('save_text', obj.save_text);
		g_form.setValue('reference_field', obj.reference_field);
		
	}
   
}

If you want to use this on multiple items you could add a property to the object you set that would be the name of the item then check if the client data exists and then check the name of the new property, etc. 

If this was helpful or correct, please be kind and remember to click appropriately! Michael Jones - Proud member of the CloudPires team!

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

jasonjones
Giga Contributor

I haven't had a chance to build the form with these constraints yet, so can't mark correct yet.

Thanks for all the advice.

Jason

jasonjones
Giga Contributor

After building the application, it was decided that the form field saving was not needed.

Thanks.
Jason