Form field value is getting cleared after setting via Form UI action.

SumitKTiwari
Tera Contributor

I am trying to store field value through UI action "Request Deletion". Once user clicks on the button it will ask for the comment, that comment has to be stored in the field in a table. 

Outcome: When user clicks on the button, the value is populating in the field and auto cleared. There is no UI policy, Client script on that field.  

Expected: once the user clicks and provide comment in the popup comment value has to store in comment field. 

 

Script :

Workspace client script : 

 

function onClick(g_form) {
var msg = getMessage("Are you sure you want to delete this evaluating firm Authoritative Source? If you click 'OK', this Authoritative Source will be sent to the ORP for approval to delete. Once approved, this action is irreversible.");
g_modal.confirm(getMessage("Confirm"), msg, function(confirmed) {
if (confirmed) {

g_modal.showFields({
title: "Please provide the rationale for requesting the deletion of this Authoritative Source.",
fields: [{
label: 'Please provide the rationale for deleting.',
type: 'textarea',
name: 'u_comment',
mandatory: true
}],
size: 'xl'
}).then(function(fieldValues) {

// alert(fieldValues.updatedFields[0].value);
g_form.setVisible('u_comment', true);
g_form.setValue('u_comment', fieldValues.updatedFields[0].value);
g_form.save();
alert('testing '+g_form.getValue('u_comment'));

// g_form.setValue('u_deletion_request','1');
g_form.submit("request_deletion1");
});

}
});
}

2 REPLIES 2

Mohith Devatte
Tera Sage
Tera Sage

Hello @SumitKTiwari ,

can you try removing g_form.submit("request_deletion1");

 

Hope this helps 

Mark my answer correct if this helps you 

Thanks

SwarnadeepNandy
Mega Sage

Hello @SumitKTiwari,

I think the problem with your code is that you are setting the value of the u_comment field twice: once in the then callback of the g_modal.showFields method, and once in the g_form.submit method. The second time, you are passing the “request_deletion1” parameter, which is not a valid value for the u_comment field. This might cause the field to be cleared after saving.

To fix this, you can either remove the g_form.setValue(‘u_comment’, fieldValues.updatedFields[0].value) line from the then callback, or remove the “request_deletion1” parameter from the g_form.submit method. Either way, you should only set the value of the u_comment field once.

Here is an example of how your code might look like after removing the g_form.setValue line:

 

function onClick(g_form) {
    var msg = getMessage(“Are you sure you want to delete this evaluating firm Authoritative Source ? If you click‘ OK’, this Authoritative Source will be sent to the ORP
        for approval to delete.Once approved, this action is irreversible.”);
    g_modal.confirm(getMessage(“Confirm”), msg, function(confirmed) {
        if (confirmed) {
            g_modal.showFields({
                title: “Please provide the rationale
                for requesting the deletion of this Authoritative Source.”,
                fields: [{
                    label: ‘Please provide the rationale
                    for deleting.’,
                    type: ‘textarea’,
                    name: ‘u_comment’,
                    mandatory: true
                }],
                size: ‘xl’
            }).then(function(fieldValues) {
                // alert(fieldValues.updatedFields[0].value); 
                g_form.setVisible(‘u_comment’, true);
                // g_form.setValue(‘u_comment’, fieldValues.updatedFields[0].value); 
                // remove this line g_form.save(); 
                alert('testing ' + g_form.getValue(‘u_comment’));
                // g_form.setValue(‘u_deletion_request’,‘1’); 
                g_form.submit();
            });
        }
    });
}

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy