Show error on Portal only when there has been any update happened

DB1
Tera Contributor

Hello all,

I have the following server side script

if(input&&input.action=='addexistingUser')
	{
var graddexuser2 = new GlideRecord('core_company'); 
		graddexuser2.addQuery('sys_id',comp1);
		graddexuser2.query();
		if(graddexuser2.next())
		{
			

			graddexuser2.u_psso_sec = input.bContacts.u_psso.value;
			graddexuser2.u_privacy_rep_gpo_rep = input.bContacts.u_privacy_rep.value;
			graddexuser2.u_billing_contact = input.bContacts.u_billing_cont.value;
			graddexuser2.u_exec_bus_contact = input.bContacts.u_exec_bus_cont.value;
			graddexuser2.u_qlty_reg_mgr = input.bContacts.u_qual_reg_mgr.value;
			graddexuser2.u_sfty_rep = input.bContacts.u_safety_rep_cont.value;
			graddexuser2.u_tech_cont = input.bContacts.u_tech_cont.value;
			graddexuser2.u_prod_cont = input.bContacts.u_product_cont.value;
			graddexuser2.u_bus_cont = input.bContacts.u_business_cont.value;
			graddexuser2.u_sup_cont = input.bContacts.u_support_cont.value;
			graddexuser2.u_edge_mon_cont = input.bContacts.u_edge_mon_cont.value;
			graddexuser2.u_hlt_prof_cont = input.bContacts.u_health_prof_cont.value;
			graddexuser2.u_crti_isue_cont = input.bContacts.u_critical_issue_cont.value;
			graddexuser2.u_prod_sec_inc_cont = input.bContacts.u_prod_priv_inc_cont.value;
			graddexuser2.u_ops_contacts = input.bContacts.u_ops_contacts.value;
			graddexuser2.update();	
			flag = 'true';
		}

		

	}
	if(flag == 'true'){
		gs.addInfoMessage("Business Contacts details have been updated");
	}
}

I need to show only when there has been some update happened.

But just because the i call the input action addexistingUser from client side and have that function called on Confirm button every time I select the button it shows the info message.

However I need that to show only when some update happens. How to do that?

From above script input.bcontacts gets all the value from client side.

 

Should I have something like if(input.bcontacts ! = '') or how to validate that some of the fields or atleast one has had an update?

 

TIA,

@Dr Atul G- LNG @Sandeep Rajput @Danish Bhairag2 @Tai Vu 

 

3 REPLIES 3

Community Alums
Not applicable

Hi @DB1 ,

 

Before you perform the update command store the existing user values in a variable/array. Then upon the update is done do the same in another variable. 
Now compare both of them & only if they aren't same set the flag as true.

 

This is what I can think of currently. Try it & let me know if it worked.


Please mark my Answer as Helpful if it works for you

Community Alums
Not applicable

Hi @DB1 ,

 

Please mark it as "Accept as Solution" and "Helpful". if this solution helped you.

 

If not, please let me know what was the issue that you're facing so that I can provide you with a solution for it.


Thanks & Regards,
Madhan Somesh.

Sandeep Rajput
Tera Patron
Tera Patron

@DB1 Since you are already querying the core_company table, you should keep compare the values stored in database with the values stored in the input object and you can set the flag if any changes found on any of the values. Accordingly you can set the flag.