Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to store the data in particular table.

praveen1231
Tera Contributor

Hello everyone, my requirement is, I had created a table called u_table_record with column label (u_user, u_name, u_email).

And also created catalog item(Demo Table) with variable User, Name, Email. When I submit the catalog item these data are mapped to to u_table_record. Please let me know if you have any idea regarding this. Thank You.

1 ACCEPTED SOLUTION

Shane J
Tera Guru

Depends on if you're using Flow (I think there's a create new Record Activity) or Workflow (probably a Script activity, using GlideRecord), but since you're using a Catalog Item you'll need to use the appropriate mechanism to:

  1. Create a record in your new table
  2. Populate that record with the values from your variables

View solution in original post

6 REPLIES 6

Hi @praveen1231 ,

 

In that case you have 3 options.

  1. Create a workflow & attach it to the catalog item under process engine tab. Add a run script activity after start node where you can use below script  then connect that activity to End Node.

 

var gr = new GlideRecord('u_table_record');
gr.initialize();
gr.u_user = current.variables.user;
gr.u_email = current.variables.email;
gr.u_name = current.variables.name;
gr.insert();

 

2. Create a new flow designer add a action called as create record & select your table (u_table_record) & map the fields of the catalog form in that action.

3. No need of any flows or Workflow. You can create an onSubmit Catalog client script & use the below code.

On Submit Client Script

 

function onSubmit() {
    //Type appropriate comment here, and begin script below

    var ga = new GlideAjax('AddRecord');
    ga.addParam('sysparm_name', 'insertRecord');
    ga.addParam('sysparm_user', g_form.getValue("user"));
	ga.addParam('sysparm_email', g_form.getValue("email"));
	ga.addParam('sysparm_name', g_form.getValue("name"));
    ga.getXMLAnswer(rollback);
}

function rollback(answer) {
    if (answer) {
		alert('Record Inserted');
    }
}

 

 

Script Include:

Client Callable : true

var AddRecord = Class.create();
AddRecord.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    insertRecord: function() {

        var user = this.getParameter('sysparm_user');
        var email = this.getParameter('sysparm_email');
        var name = this.getParameter('sysparm_name');

        var gr = new GlideRecord('u_table_record');
        gr.initialize();
        gr.u_user = user;
        gr.u_email = email;
        gr.u_name = name;
        gr.insert();
        return 'true';


    },
    type: 'AddRecord'
});

 Mark my answer helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish

 

 

Shane J
Tera Guru

Depends on if you're using Flow (I think there's a create new Record Activity) or Workflow (probably a Script activity, using GlideRecord), but since you're using a Catalog Item you'll need to use the appropriate mechanism to:

  1. Create a record in your new table
  2. Populate that record with the values from your variables