Archived Content: This information is no longer maintained and is provided "as is" for your convenience.
Reference
Creating Records
Return to TRIM Web Service Samples
When a new record (or other object) is created using the web service layer, the URI for the resulting object is returned in the FetchResult object of the TrimResponse. This URI can also then be used to create child objects.
The example below illustrates how this is done.
//Create a record and return a URI RecordTypeStringSelect recordtypeselect = new RecordTypeStringSelect(); recordtypeselect.Arg = "Document"; //get Document record type from demodb recordtypeselect.Id = "recordtype"; FetchInjectionUri recordtypeuri = new FetchInjectionUri(); recordtypeuri.Id = "recordtype"; //get URI of RecordTypeStringSelect (rts) operation InputProperty recordname = new InputProperty(); recordname.Name = "rectitle"; //set title of new record recordname.Val = "New Record"; InputProperty recordtype = new InputProperty(); recordtype.Name = "recRecordType"; recordtype.Val = "inject:recordtype"; //set recordtype of new record using injection from RecordTypeStringSelect (rts) operation above Create createrecord = new Create(); createrecord.TrimObjectType = "record"; createrecord.Id = "createrecord"; createrecord.Items = new InputProperty [] {recordtype, recordname}; //create new record with recordtype and recordname input properties FetchInjectionUri createdrecorduri = new FetchInjectionUri(); createdrecorduri.Id = "createrecord"; //get URI of newly created record
From this point you could use “inject: createrecord” to insert the new record’s URI into any further Operations pertaining to the newly created record.
TrimRequest trimctRequest = new TrimRequest(); trimctRequest.Items = new Operation[] {recordtypeselect, recordtypeuri, createrecord, createdrecorduri}; //create trim request which gets the rcord type, its URI, creates a new record using the record type and gets the newly created record's uri TrimResponse trimctResponse = engine.Execute (trimctRequest); foreach (Result trimctresult in trimctResponse.Items ) //how to interrogate the TrimResponse object and get URI from a fetch result. { switch (trimctresult.GetType().Name.ToString()) { case "EndResponse": // Code to handle the EndResponse txtResults.Text += "EndResponse!\r\n"; break; case "SuccessResult": // Code to handle the SuccessResult txtResults.Text += "SuccessResult!\r\n"; break; case "FetchResult": // Code to handle the FecthResult txtResults.Text += "FetchResult!\r\n"; FetchResult fetchRes = (FetchResult) trimctresult; TrimObject [] objs = fetchRes.Objects; foreach (TrimObject tobj in objs) { txtResults.Text += tobj.Uri.ToString () + "\r\n"; } break; case "FetchInjectionUriResult" : // Code to handle the FetchInjectionUriResult txtResults.Text += "FetchInjectionuriResult!\r\n"; FetchInjectionUriResult fiuresult = (FetchInjectionUriResult) trimctresult; txtResults.Text += fiuresult.Uri + "\r\n"; break; case "ErrorResult": // Code to handle the ErrorResult txtResults.Text += "ErrorResult!\r\n"; ErrorResult err = (ErrorResult) trimctresult; txtResults.Text += err.Message + "\r\n"; break; default: // Code to handle whatever else, etc… txtResults.Text += "Other Result!\r\n"; txtResults.Text += trimctresult.GetType().Name.ToString()+ "\r\n"; break; } }