create record in backend form from service catalog request

tiyasa
Giga Expert

Hello,

I have a Catalog to submit a request for Hardware. User can select New or Existing. This is a reference to backend table. I want to create a new record in alm_hardware.do when user selects new and update an existing request .

To achieve this, I have a client script for each condition , new and existing , sample as below. Unfortunately, it doesn't work. Can someone please show me a direction . Thanks in Advance.

function onSubmit() {

  var select = g_form.getValue('en_select');

  var gr = new GlideRecord('alm_hardware');

  while(select == 'existing'){

  gr.addQuery('model_category','=','en_model_category');

  gr.addQuery('model','=','en_model');

  gr.addQuery('asset_tag','=','en_asset_tag');

  gr.query();

  if(gr.next()){

  gr.model_category = en_model_category;

  gr.model = en_model;

  gr.asset_tag = en_asset_tag;

  gr.location = en_location;

  gr.company = en_company;

  gr.u_hier2 = en_division;

  gr.u_hier4 = en_hier4;

  gr.update();

  }

  }

}

1 ACCEPTED SOLUTION

Maybe you want to do something like this:



function onSubmit() {


  var select = g_form.getValue('en_select');


  if(select == 'existing'){


  var gr = new GlideRecord('alm_hardware');


  gr.addQuery('model_category','=',g_form.getValue('en_model_category'));


  gr.addQuery('model','=',g_form.getValue('en_model'));


  gr.addQuery('asset_tag','=',g_form.getValue('en_asset_tag'));


  gr.query();


  if(gr.next()){


  gr.location = g_form.getValue('en_location');


  gr.company = g_form.getValue('en_company');


  gr.u_hier2 = g_form.getValue('en_division');


  gr.u_hier4 = g_form.getValue('en_hier4');


  gr.update();


  }


  }


}



Thanks,


Deepak


Hit Like, Helpful or Correct based upon the impact of the response


View solution in original post

15 REPLIES 15

Deepa Srivastav
Kilo Sage

You want to create new record, right? If yes use..use     gr.insert();   instead of gr.update(); ...



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Hi Tiyasa,


I am not sure if i understand your requirement here. Is the user, from the catalog form, directly updating the record on the alm_hardware table? Or a Request would be generated that would go through a range of approvals and then finally update the record on the Hardware table?


From the Catalog, If the user select the option "New", he fills in details and a record is pushed to alm_hardware. The catalog follows its own wokflow, but the user doesnot see it. The creation of new record in alm_hardware is done in the background.


function onSubmit() {


  var select = g_form.getValue('en_select');


alert (select); // check what select is showing


if(select == 'new'){


  var gr = new GlideRecord('alm_hardware');


  gr.addQuery('model_category','=','en_model_category');


  gr.addQuery('model','=','en_model');


  gr.addQuery('asset_tag','=','en_asset_tag');


  gr.query();


  if(gr.next()){


  var gri = new GlideRecord('alm_hardware');


  gri.initialize();


  gri.model_category = g_form.getValue('en_model_category');


  gri.model = g_form.getValue('en_model');


  gri.asset_tag = g_form.getValue('en_asset_tag');


  Similarly for the others


  gri.location =


  gri.company =


  gri.u_hier2 =


  gri.u_hier4 =


  gri.insert();


  }


  }


}