Sage CRM - There is method to retrieve the ID on the recently created record when using CRM.CreateRecord object? - sage-crm

Given this code:
var NewComm = CRM.CreateRecord("Communication");
NewComm("Comm_ChannelId") = Request.Form("chanId");
NewComm("Comm_Type") = "Appointment";
NewComm("Comm_DateTime") = Request.Form("initialHour");
NewComm("Comm_Status") = "Pending";
NewComm("Comm_Priority") = "Normal";
NewComm("Comm_Action") = "Meeting";
NewComm("Comm_SecTerr") = Request.Form("secTerr");
NewComm("Comm_Subject") = "No Subject";
NewComm("Comm_Note") = "No notes";
NewComm.SaveChanges();
There is a method of the CreateRecord Object to retrieve the ID of the recently created record?

Once you have created the new record, the Id becomes available in the object. Using your example above, you can simply get the Id with this code:
NewComm.SaveChanges();
var CommId = NewComm("Comm_CommunicationId");
This applies to any record type with the same method.
Six Ticks Support

Related

How to create multi items/records or save item/record array at one time in client script file

I want to create multiple records at the same time using client script. This is what I'm doing:
var ceateDatasource = app.datasources.Reservation.modes.create;
var newItem = ceateDatasource.item;
newItem.User = user; //'eric'
newItem.Description = description; //'000'
newItem.Location_Lab_fk = lab.value.Id; //'T'
newItem.Area_fk = area.value.Id; //'L'
newItem.Equipment_fk = equipment.value.Id; //'S'
for(var i = 0 ; i < 3; i ++) {
newItem.Start_Date = startDate;
newItem.Start_Hours = '03';
newItem.Start_Minutes = '00';
newItem.End_Date = startDate;
newItem.End_Hours = '23';
newItem.End_Minutes = '30';
// Create the new item
ceateDatasource.createItem();
}
But the result I'm getting is this one:
The three records are created but the only the first one has data. The other two records have empty values on their fields. How can I achieve this?
Thanks.
Update(2019-3-27):
I was able to make it work by putting everything inside the for loop block. However, I have another question.
Is there any method like the below sample code?
var recordData = [Data1, Data2, Data3]
var ceateDatasource;
var newItem = new Array(recordData.length) ;
for(var i = 0 ; i < recordData.length; i ++) {
ceateDatasource = app.datasources.Reservation.modes.create;
newItem[i] = ceateDatasource.item;
newItem[i].User = recordData[i].user;
newItem[i].Description = recordData[i].Description;
newItem[i].Location_Lab_fk = recordData[i].Location_Lab_fk;
newItem[i].Area_fk = recordData[i].Area_fk;
newItem[i].Equipment_fk = recordData[i].Equipment_fk;
newItem[i].Start_Date = recordData[i].Start_Date;
newItem[i].Start_Hours = recordData[i].Start_Hours;
newItem[i].Start_Minutes = recordData[i].Start_Minutes;
newItem[i].End_Date = recordData[i].End_Date;
newItem[i].End_Hours = recordData[i].End_Hours;
newItem[i].End_Minutes = recordData[i].End_Minutes;
}
// Create the new item
ceateDatasource.createItem();
First, it prepares an array 'newItem' and only calls 'ceateDatasource.createItem()' one time to save all new records(or items).
I try to use this method, but it only saves the last record 'newItem[3]'.
I need to write a callback function in 'ceateDatasource.createItem()' but Google App Maker always show a warning "Don't make functions within a loop". So, are there any methods to call 'createItem()' one time to save several records? Or are there some functions like 'array.push' which can be used?
Thanks.
As per AppMaker's official documentation:
A create datasource is a datasource used to create items in a particular data source. Its item property is always populated by a draft item which can be bound to or set programmatically.
What you are trying to do is create three items off the same draft item. That why you see the result you get. If you want to create multiple items, you need to create a draft item for each one, hence all you need to do is put all your code inside the for loop.
for(var i = 0 ; i < 3; i ++) {
var ceateDatasource = app.datasources.Reservation.modes.create;
var newItem = ceateDatasource.item;
newItem.User = user; //'eric'
newItem.Description = description; //'000'
newItem.Location_Lab_fk = lab.value.Id; //'T'
newItem.Area_fk = area.value.Id; //'L'
newItem.Equipment_fk = equipment.value.Id; //'S'
newItem.Start_Date = startDate;
newItem.Start_Hours = '03';
newItem.Start_Minutes = '00';
newItem.End_Date = startDate;
newItem.End_Hours = '23';
newItem.End_Minutes = '30';
// Create the new item
ceateDatasource.createItem();
}
If you want to save several records at the same time using client script, then what you are looking for is the Manual Save Mode. So all you have to do is go to your model's datasource and click on the checkbox "Manual Save Mode".
Then use the same code as above. The only difference is that in order to persist the changes to the server, you need to explicitly save changes. So all you have to do is add the following after the for loop block:
app.datasources.Reservation.saveChanges(function(){
//TODO: Callback handler
});

How to get value from dictionary session

i have stored multiple values in session using dictionary like below
var get_values = new Dictionary();
get_values["name"] = model.Name; ;
get_values["address"] = model.Address;
get_values["phone"] = model.Phone;
get_values["email"] = model.Email;
Session["sess_values"] = get_values;
now i want to get values from session one by one. my question is how to get values from session like name, address etc.?
just like any normal dictionary
//you get your sesssion
var sessionDictionary =Session["sess_values"] as Dictionary<string, string>;
//then get the value, example for name
var TheName = sessionDictionary["name"];

Maximo Anywhere - Lookup Filter issue

I am working on Maximo Anywhere 7.5.2 (Work Execution app). I need to filter the lookup values based on some conditions within Anywhere.
Ex: Lets consider, I have textfield which can have A or B value only, If it is A from Maximo, then the lookup field should show (P,Q,R,S) and if it is B, Lookup should show (P,Q) only.
This is trickier than you think, because you'll need to write your own code to execute to filter the subsequent lookup. For an example you can look at this code in WODetailHandler.filterAssetForLookup method.
filterAssetForLookup: function(eventContext){
var additionalasset = CommonHandler._getAdditionalResource(eventContext,'additionalasset');
additionalasset._lookupFilter = null;
//save the current asset so we can reset it if the user has to revert the value
var workOrderSet = CommonHandler._getAdditionalResource(eventContext,"workOrder");
if(workOrderSet.getCurrentRecord() != null){
this.curAsset = workOrderSet.getCurrentRecord().get("asset");
this.curAssetDesc = workOrderSet.getCurrentRecord().get("assetdesc");
this.curAssetld = workOrderSet.getCurrentRecord().get("assetld");
}
var siteid = CommonHandler._getWorkorderSiteId(eventContext);
if(siteid == null){
siteid = UserManager.getInfo("defsite");
}
var filter = [];
filter.push({siteid: siteid});
additionalasset.lookupFilter = filter;
},
Then you attach this filter in the filterMethod in the app.xml.
<lookup filterClass="application.handlers.WODetailHandler" filterMethod="filterAssetForLookup" id="WorkExecution.AssetLookup" label="Select Asset" resource="additionalasset">

How to get spcial item in QuickBooks online by Programming

I've inserted three Customer items into QuickBooks online. I want to find a special item by ids and modify one of the attributes' value. I want to accomplish this by coding in backstage of a application. How can I do this?
This is the connection code that I have:
realmId = HttpContext.Current.Session["realm"].ToString();
accessToken = HttpContext.Current.Session["accessToken"].ToString();
accessTokenSecret = HttpContext.Current.Session["accessTokenSecret"].ToString();
consumerKey = ConfigurationManager.AppSettings["consumerKey"].ToString(CultureInfo.InvariantCulture);
consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
dataSourcetype = IntuitServicesType.QBO;
OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
ServiceContext context = new ServiceContext(oauthValidator, realmId, dataSourcetype);
DataServices commonService = new DataServices(context);
You can query for customers as follows:
//search based on customer name
var qbdCustomerQuery1 = new Intuit.Ipp.Data.Qbd.CustomerQuery();
qbdCustomerQuery1.Item1ElementName = Intuit.Ipp.Data.Qbd.Item1ChoiceType.FirstLastInside; //Item1ChoiceType.FirstLastEnd //Item1ChoiceType.FirstLastStart
qbdCustomerQuery1.Item1 = "Popeye";
List<Intuit.Ipp.Data.Qbd.Customer> CustomerQueryResult = qbdCustomerQuery1.ExecuteQuery<Intuit.Ipp.Data.Qbd.Customer>(context).ToList<Intuit.Ipp.Data.Qbd.Customer>();
//search based on customer id
Intuit.Ipp.Data.Qbo.Customer qboCustomer = new Intuit.Ipp.Data.Qbo.Customer();
qboCustomer.Id = new IdType() { idDomain = Intuit.Ipp.Data.Qbo.idDomainEnum.QBO, Value = "3" };
IEnumerable<Intuit.Ipp.Data.Qbo.Customer> qboCustomerResults = commonService.FindById(qboCustomer) as IEnumerable<Intuit.Ipp.Data.Qbo.Customer>;
Use the resultset to get the customer object. Modify the values and call Update:
https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits/0100_ipp_.net_devkit/0299_synchronous_calls/0001_data_service_apis

Getting Trusteedata error when send the item back to author

I am trying to send the item back to auther in workflow using coresrvice, the below is my code, am getting compile error on casting betweento usrdata to linktotrusteedata.
WorkItemData workitem = (WorkItemData)csClient.Read(workitemid, readoption);
ProcessInstanceData processInstance = (ProcessInstanceData)csClient.Read(workitem.Process.IdRef, readoption);
IEnumerable<ActivityData> ieActivities = processInstance.Activities;
if (ieActivities != null)
{
ActivityInstanceData targetactivity = (ActivityInstanceData)csClient.Read(processInstance.Activities[0].Id, readoption);
UserData lastperformer = (UserData)csClient.Read(processInstance.Activities[0].Owner.IdRef, readoption);
ActivityFinishData finishData = new ActivityFinishData();
finishData.Message = "Finished automatically";
finishData.NextAssignee = lastperformer;
csClient.FinishActivity(targetactivity.Id, finishData, readoption);
csClient.Close();
}
The NextAssignee property is of type Link<TrusteeData> but you are setting it to a UserData object. You probably need to create a new Link and fill in the ID and Title of it.
This should work (untested):
[...]
Link<UserData> lastperformer = processInstance.Activities[0].Owner;
ActivityFinishData finishData = new ActivityFinishData();
finishData.Message = "Finished automatically";
finishData.NextAssignee = new Link<TrusteeData> { Id = lastperformer.Id, Title = lastperformer.Title };
csClient.FinishActivity(targetactivity.Id, finishData, readoption);
[...]
It's also possible that it can work if you just set NextAssignee to the lastperformer variable, since UserData inherits from TrusteeData - but I'm not certain about that. Give it a try?
You have the LinkToUserData object already, so can't you assign processInstance.Activities[0].Owner to finishData.NextAssignee, or use the Owner property (LinkToUserData) to construct a new data object?
Or is there a specific reason you read the UserData?

Resources