Refresh the form in server side

Hemachithra
Tera Contributor

Hi, I want to refresh my REQ form automatically once the request is created as the approvers in the approval tab appears only after I refresh it manually .

1 ACCEPTED SOLUTION

Martin Ivanov
Giga Sage
Giga Sage

Here is something that I created in the past. It resided in a Client script and it was refreshing the related list of my choice. here is the script with a delay of 4 seconds. check if you can adapt this to your case. 

 

if(!g_form.getValue('contract')){
		return;
	}

	setTimeout(function(){ 

		if(!g_form.isNewRecord()){

			var listName =g_form.getTableName()+'.REL:70e80f390a0a0b1b0035a51d8bbfd32c';
			var list = GlideList2.get(listName);
// 			if (list){
// 				g_form.addInfoMessage('List selected');
// 			}else{
// 				g_form.addInfoMessage('List not selected');
// 			}

			var filter = 'contract='+g_form.getValue('contract')+'^end_date>=javascript:gs.beginningOfToday()^start_date<=javascript:gs.endOfToday()';
			list.setFilterAndRefresh(filter);
		}

	}, 4000);

Please Mark Correct AND Helpful. Thanks!

Martin Ivanov
2022 Community Rising Star


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

View solution in original post

4 REPLIES 4

Martin Ivanov
Giga Sage
Giga Sage

Here is something that I created in the past. It resided in a Client script and it was refreshing the related list of my choice. here is the script with a delay of 4 seconds. check if you can adapt this to your case. 

 

if(!g_form.getValue('contract')){
		return;
	}

	setTimeout(function(){ 

		if(!g_form.isNewRecord()){

			var listName =g_form.getTableName()+'.REL:70e80f390a0a0b1b0035a51d8bbfd32c';
			var list = GlideList2.get(listName);
// 			if (list){
// 				g_form.addInfoMessage('List selected');
// 			}else{
// 				g_form.addInfoMessage('List not selected');
// 			}

			var filter = 'contract='+g_form.getValue('contract')+'^end_date>=javascript:gs.beginningOfToday()^start_date<=javascript:gs.endOfToday()';
			list.setFilterAndRefresh(filter);
		}

	}, 4000);

Please Mark Correct AND Helpful. Thanks!

Martin Ivanov
2022 Community Rising Star


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

with the GlideList2 api you have some method that can help you refresh only the related lists


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

Martin Ivanov
Giga Sage
Giga Sage

Hi. If your issue is resolved and my response has helped, plese consider marking Correct and Helpful. Thanks!

Martin Ivanov

2022 Community Rising Star

 


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

Martin Ivanov
Giga Sage
Giga Sage

Hi. Thanks for marking correct, but please mark the original response, as it might help some other people.


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024