filed validation on one table and data pass will be on another table

sushma9
Tera Contributor

Hi All,

 Is there a possibility where the filed validation on one table and once the validation is done can we pass the data to a filed in  other table  .

Ex: i am validating a Filed through client script  using script include and glide ajax .Once the data is returns from the script include to ajax and validation is done  then i need to pass that data to   filed in another table . Is it possible ?

1 ACCEPTED SOLUTION

Hello @sushma9 

 

You can send the url link to another field of another table using gliderecord.

 

gr.field_name = current.url_field;

 

In this way.

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

View solution in original post

9 REPLIES 9

@Samaksh Wani 
with the br i have done the validation and once the validation is done  can i send the the url link to that filed in other table

Hello @sushma9 

 

You can send the url link to another field of another table using gliderecord.

 

gr.field_name = current.url_field;

 

In this way.

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

Community Alums
Not applicable

Hi @sushma9 ,

 

To validate data in one table and pass the validated data to a field in another table using client scripts, script includes, and GlideAjax in ServiceNow:

Step 1: Create a Script Include for Validation

var ValidateDataScriptInclude = Class.create();
ValidateDataScriptInclude.prototype = {
    validateData: function(dataToValidate) {
        // Validation logic - replace this with your own validation rules
        // For demonstration purposes, assuming simple validation (e.g., ensuring the data is not empty)
        if (dataToValidate) {
            return dataToValidate; // Data is valid
        } else {
            return null; // Data is invalid
        }
    },

    type: 'ValidateDataScriptInclude'
};

 

Step 2: Client Script to Trigger Validation and Pass Data to Another Table

** Client Script (on Table 'A'):  Assuming you have a form on Table A with a field 'fieldToValidate' and you want to pass validated data to a field in Table B.

function onSubmit() {
    var valueToValidate = g_form.getValue('fieldToValidate');
    var validation = new GlideAjax('ValidateDataScriptInclude');
    validation.addParam('sysparm_name', 'validateData');
    validation.addParam('sysparm_dataToValidate', valueToValidate);
    validation.getXMLAnswer(function(response) {
        // Response from validation
        var validatedData = response;
        if (validatedData) {
            // Assuming 'TableB' is the table name and 'fieldInTableB' is the field name in Table B
            var gr = new GlideRecord('TableB');
            gr.initialize();
            gr.fieldInTableB = validatedData;
            gr.insert(); // or gr.update() if updating existing record
        } else {
            // Validation failed
            alert('Validation failed!');
        }
    });
}

 

Remember, this example provides a basic structure and logic for performing validation in one table and passing validated data to another table. Customize the validation rules and table/field names according to your specific use case and data structure in ServiceNow.

 

If you found this helpful, a 'like' and 'solution acceptance' is the secret handshake of appreciation!

-Prasad

@Community Alums 

As per the best paractice we should not write the glide record on the client side right 

Community Alums
Not applicable

Yes, @sushma9 agreed.

Validation Process:

Use a Client Script along with a Script Include to validate a field's value.
Data Handling:

Upon successful validation:
Implement a function within the same script to update/insert the validated data into another table.
This approach allows you to validate data using a Client Script and a Script Include, and if the validation passes, handle the data manipulation for another table within the same script.

If this helps you out, feel free to give it a thumbs up or mark it as the accepted solution!

 

Thanks,

Prasad