Updating records on custom table

cre1014
Kilo Expert

In creating a new service catalog item, I created a custom table that is populated with all of the variable information to make for easier reporting. (The Variable Ownership table for us is rather huge.) I have the business rule that successfully captures all of the entered data into the variables and writes them to the respective columns in the new custom table, using the RITM number as the link.

The issue that I'm having is with updating these records. There are instances where our support teams will update the variable information at the TASK level, and these changes need to be reflected in the new custom table that I initially created. Since the variables on the TASK form are the same as the ones on the RITM, I was hoping this would be fairly straight forward. However, this is the part that isn't quite working correctly - my logs state that the update() that I have at the end of the script has been reached, but nothing about the record in the table actually updates.

Below is the code for the attempted updating of the record via the TASK. For the sake of brevity, I only left two variables as an example.Is this even possible to do? What have I not set up correctly in order to get this to work?

/**

* Expense Authorization Request

**/

if (current.request_item.cat_item.getDisplayValue() == "Expense Authorization Request"){

  var gr = new GlideRecord("u_expense_authorization_reques");

        var updateRecord = false;

  gr.addQuery('u_request_item', current.request_item.sys_id);

  gr.query();

  if (gr.next()) {

  //set flag to indicate record already exists

  updateRecord = true;

  }

  gr.initialize();

//Copy all variable values to the record

gr.urequest_item = current.request_item.sys_id;

  gr.u_additional_info = current.request_item.variable_pool.add_info;

  gr.u_additional_review_required = current.request_item.variable_pool.add_review_req;

  gr.u_approval_to_move_forward = current.request_item.variable_pool.app_move_forward;

 

if (updateRecord == true) {

        // Update

gs.log("I've reached the update step");

        gr.update()

  } else {

    //Insert the record

          gr.insert();

    }

}

5 REPLIES 5

xiaix
Tera Guru

Here is the code you need:



/**


* Expense Authorization Request


**/


if (current.request_item.cat_item.getDisplayValue() == "Expense Authorization Request")


{


      var gr = new GlideRecord("u_expense_authorization_reques");


      gr.addQuery('u_request_item', current.request_item.sys_id);


      gr.query();


      if (gr.next())


      {


              //Copy all variable values to the record


              gr.urequest_item = current.request_item.sys_id;


              gr.u_additional_info = current.request_item.variable_pool.add_info;


              gr.u_additional_review_required = current.request_item.variable_pool.add_review_req;


              gr.u_approval_to_move_forward = current.request_item.variable_pool.app_move_forward;


              gr.update();


      }


      else


      {


              gr = new GlideRecord("u_expense_authorization_reques");


              gr.initialize();


              gr.urequest_item = current.request_item.sys_id;


              gr.u_additional_info = current.request_item.variable_pool.add_info;


              gr.u_additional_review_required = current.request_item.variable_pool.add_review_req;


              gr.u_approval_to_move_forward = current.request_item.variable_pool.app_move_forward;


              gr.insert();


      }


}



Only question I have is, are you missing a "t" in your table name?



Should u_expense_authorization_reques be u_expense_authorization_request ?