Using the UpdateObject Web Method
6 min
this web method updates a single object by changing its field values, and may also establish or break relationships with other objects the auto fill, calculated, save, and business rules run during the update and may trigger additional field changes validation rules are also executed and they might block the update operation if the resulting object field values do not pass the validation the order of operations is preserved during the update request syntax frsheatintegrationupdateboresponse updateobject(string sessionkey, string tenantid, objectcommanddata commanddata) parameters sessionkey the session key from the connect web method tenantid the tenant for which the session key is authenticated commanddata a structure containing information about the creation request return value frsheatintegrationupdateboresponse object, defined as follows public class frsheatintegrationupdateboresponse { public string status { get; set; } public string exceptionreason { get; set; } public string recid { get; set; } public webservicebusinessobject obj { get; set; } } the frsheatintegrationupdateboresponse class has the following fields status provides a status about the state of the operation the table below contains a full description of the available status values exceptionreason contains exception information, if the application throws an exception when running this web method recid the rec id of the updated record, if the status of the web method is "success" obj returns the updated record as an webservicebusinessobject object, if the business object record is updated successfully the following table lists the available status values and describes how to interpret them status explanation success successfully updated the business object the recid field of the response object contains the rec id of the newly created record the obj field references the newly created webservicebusinessobject error cannot create the business object the recid and obj fields are null inspect the corresponding exceptionreason field to determine why the web method has failed one typical error is table not found , which occurs when the specified business object does not exist in the tenant ensure that the name of the business object is spelled properly another common error is that the specified field does not exist for the business object the error message is objecttablemap field \<fieldname> is not found in table \<business object># ensure that the field name is spelled correctly, and that it is defined for the specified business object another common error is to specify a value for a field that does not exist in the associated validation list the error message is \<businessobject> \<field> `\<fieldvalue>` is not in the validation list to specify datetime values, specify the string value using iso 8601 format the value itself should be relative to utc the datetime value can be specified in one of the following two ways yyyy mm dd hh\ mm yyyy mm ddthh\ mm use either a space character or "t" character to separate the date and time values the following are two examples of specifying a datetime value of march 26th, 2013, 18 38 utc, relative to the above two formats 2013 03 26 18 38 2013 03 26 t 18 38 example the following example locates an existing change record and ci computer record, by means of the search web method, and links the two records together by using the updateobject web method // first, locate the change record to update, using the changenumber // (e g change 21) objectquerydefinition changequery = new objectquerydefinition(); // just retrieve only the recid field for the change record fieldclass\[] changefieldobjects = new fieldclass\[] { new fieldclass() { name = "recid", type = "text" } }; changequery select = new selectclass(); changequery select fields = changefieldobjects; changequery from = new fromclass(); // search for the record against the change object changequery from object = "change"; changequery where = new ruleclass\[] { new ruleclass() { // provide the criteria to search for the change // here, we will search for the change by its changenumber condition = "=", field = "changenumber", value = "21" } }; // pass in the objectquerydefinition for the query frsheatintegrationsearchresponse changesearchresponse = frsvc search(authsessionkey, tenantid, changequery); webservicebusinessobject\[]\[] changelist = changesearchresponse objlist; // assuming that the change record is uniquely identified by the // changenumber, and because the above query does not join with other // tables, we should be able to locate the change record, by accessing // changelist\[0]\[0], in the list of list of webservicebusinessobjects webservicebusinessobject change = changelist\[0]\[0]; string changerecid = change recid; // now locate the ci computer record, to link with the existing change // here we will attempt to locate the ci computer record with // the name of "apac depot serv01" and retrieve its recid objectquerydefinition ciquery = new objectquerydefinition(); // just retrieve only the recid field of the ci for the matching result fieldclass\[] cifieldobjects = new fieldclass\[] { new fieldclass() { name = "recid", type = "text" } }; ciquery select = new selectclass(); ciquery select fields = cifieldobjects; ciquery from = new fromclass(); // search for the record against the ci computer member object ciquery from object = "ci computer"; ciquery where = new ruleclass\[] { // search for the ci computer by its name new ruleclass() { condition = "=", field = "name", value = "emea exch serv01" } }; // pass in the objectquerydefinition for the query frsheatintegrationsearchresponse cisearchresponse = frsvc search(authsessionkey, tenantid, ciquery); webservicebusinessobject\[]\[] cilist = cisearchresponse objlist; // assuming that the ci record is uniquely identified by name, and // because the above query does not join with other tables, we should // be able to locate the ci record, by accessing cilist\[0]\[0], in the // list of list of webservicebusinessobjects webservicebusinessobject ci = cilist\[0]\[0]; // since we are only retrieving the recid field for ci, it will appear // as the first item in the list of fields, i e ci fieldvalues\[0] string cirecid = (string)ci fieldvalues\[0] value; // at this point, we now have the recid of the change and ci records, // and can proceed with the update // for the objectcommanddata, use the changerecid value that was // determined above, for looking up the record to update objectcommanddata data = new objectcommanddata(); data objecttype = "change#"; data objectid = changerecid; list\<objectcommanddatafieldvalue> datafields = new list\<objectcommanddatafieldvalue>(); dictionary\<string, object> fields = new dictionary\<string, object>(); // to demonstrate that the existing field value can be updated, set the // urgency of the existing change record to "high" fields\["urgency"] = "medium"; // update the cabvoteexpirationdatetime to a specific date/time value fields\["cabvoteexpirationdatetime"] = "2013 03 26 18 38 30 "; foreach (string key in fields keys) { datafields add(new objectcommanddatafieldvalue() { name = key, value = fields\[key] tostring() }); } data fields = datafields toarray(); data linktoexistent = new linkentry\[] { new linkentry() { action = "link", relation = "", relatedobjecttype = "ci#", relatedobjectid = cirecid } }; frsheatintegrationupdateboresponse response = frsvc updateobject(authsessionkey, tenantid, data); if (response exceptionreason != null) { console writeline("encountered the following error while updating the record ", response exceptionreason); }
