Values not getting saved from UI macro to the ServiceNow fields

DH7
Tera Contributor

We have two UI macros "Apply Default Button" and "Default Mappings".'

 

"Apply Default Button" has a button called "Apply Defaults"

 

"Default Mappings" has an HTML table with two columns, one "Source" and another one "Destination". The values of this HTML table are stored in the ServiceNow string field called "Mapping data".

 

Both "Apply Default Button" and "Default Mappings" are present in the same form view section.

When the "Apply Defaults" button is clicked, we remove the existing HTML table every time from the "Default Mappings" and create a new HTML table, then we save the default values to the ServiceNow string field "Mapping data" and populate those default values in the newly created HTML table.

 

Now when the "Apply Defaults" button is clicked, and save the default mapping values in the ServiceNow "Mapping data" field and populate them in the new HTML tables, and when we try to save the record, it doesn't save those default values, even not in the ServiceNow string field "Mapping data".

 

However, if we manually type the values in the HTML table, which will get saved in the "Mapping data" field also, and then on saving the record, those values are getting saved.

 

Also, when the "Apply Defaults" button is pressed, and if we save the values by adding space at the end from the client side, like default + " ", then it works fine.

 

On further investigating, if we do not remove the existing HTML table, then also those default values are getting saved on clicking the "Apply Defaults" button.

 

This issue occurs only after the ServiceNow Tokyo patch-4a and in the Utah instances and is working fine for the Rome and San Deigo instances.

 

Note:
- We do require the HTML table from the "Default Mappings" UI macro to be removed when the "Apply Defaults" button is clicked.

 

Does anyone have any idea why removing the HTML table does not save the default values?

2 REPLIES 2

Ratnakar7
Mega Sage
Mega Sage

Hi @DH7 ,

 

It is possible that the issue is related to the timing of when the values are being saved. When the "Apply Defaults" button is clicked, the existing HTML table is removed, and a new HTML table is created with default values. However, if the record is saved immediately after creating the new HTML table, it is possible that the default values may not have been saved yet.

One possible solution is to ensure that the default values are saved before attempting to save the record. This can be done by using asynchronous JavaScript to save the default values to the ServiceNow string field "Mapping data", and then triggering the save of the record once the default values have been saved.

Another possibility is that the issue is related to the way the HTML table is being created and populated. It is possible that the HTML table is not being created or populated correctly, which could cause issues when attempting to save the default values. To verify this, you may want to review the code that creates and populates the HTML table to ensure that it is correct.

 

If my response helps you to resolve the issue close the question by Accepting solution and hit 👍thumb icon. From Correct answers others will get benefited in future.

 

Thanks,

Ratnakar

DH7
Tera Contributor

Hi @Ratnakar7 ,

This issue doesn't seem to be related to the timing, as even after waiting for some time before the record is saved, those default values are not getting saved.

One thing to note here is that when Apply Defaults is clicked then at that time default values are getting saved to "Mapping Data" ServiceNow string fields from the client side using `g_form.setValue()`, and after that when I try to save the record, which ideally should save those default values in the Mapping Data field in the backend, those default values do not get retains.