widget data to record producer

SNOW User8
Giga Guru

Is there any way to retrieve a widget data and create a new Record Producer based on that data.

If someone have a solution please advice me to achieve this.

        find_real_file.png

I want to create a new Record Producer based on this details. (New Record Producer as a Name) and others as Variables.

Regards,

Anna.

1 ACCEPTED SOLUTION

Kristoffer Mon1
Giga Expert

Hi Anna,



It appears you and I have similar requirements.   My widget contains a table, with basic functionality like adding rows and inline editing.



The only way i've discovered to pass the data object is create a hidden catalog variable to store the serialized data object.



Widget client script:



$scope.page.g_form.setValue("hidden_widget_value", angular.toJson(c.data.notes));




Then on catalog client script you could do something like :


function onSubmit() {


        var data_from_widget = g_form.getValue('hidden_widget_value');



        /* parse string to object, then iterate object to insert records into table */


}


View solution in original post

15 REPLIES 15

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

I am not sure I am following your use case, but have you considered Service Creator:


Service Creator



This is a "self-service" way to create new services in the Service Catalog.


Kristoffer Mon1
Giga Expert

Hi Anna,



It appears you and I have similar requirements.   My widget contains a table, with basic functionality like adding rows and inline editing.



The only way i've discovered to pass the data object is create a hidden catalog variable to store the serialized data object.



Widget client script:



$scope.page.g_form.setValue("hidden_widget_value", angular.toJson(c.data.notes));




Then on catalog client script you could do something like :


function onSubmit() {


        var data_from_widget = g_form.getValue('hidden_widget_value');



        /* parse string to object, then iterate object to insert records into table */


}


Hi kristoffermoncada



It's really more helpful.


I can get the data, but unable to set to the newly created Record Producer variable.


Also can you please tell me how to parse string to object, then iterate object to insert records into table.



Regards,


Anna.


Hi annasilva



I've created a business rule that runs the following script on insert into "table_a":



(function executeRule(current, previous /*null when async*/) {



  var data_from_widget = current.getValue('widget_value');


  gs.info("[!] data_from_widget = " + data_from_widget);



  var notes = JSON.parse(data_from_widget); //parse string into JSON


  //gs.info(notes);




  for (var i = 0; i < notes.length; i++){


  gs.info('adding record' + i);


  gs.info('notes[' + i + '].title=' + notes[i].class_subject);


  gs.info('notes[' + i + '].note=' + notes[i].catalog_number);


  var newNote = new GlideRecord('table_b');


  newNote.initialize();



  if(notes[i].class_subject != null)


  newNote.class_subject = notes[i].class_subject.toString();



  if(notes[i].catalog_number != null)


  newNote.catalog_number = notes[i].catalog_number.toString();



  newNote.element_id = current.getValue('sys_id');


  newNote.insert();



  }



})(current, previous);



The idea here being that the sys_id of the current record, is used as the "element_id" of the newly inserted records into "table_b"; of which a relationship between the two tables can be made.



Hope this helps.