I am trying to get activities for cases from different instance with all File Attachments and Notes attached to the activities. I have tried with different ways, but unfortunately none of them has worked. Can anyone please suggest what is the best way to get all file attachments and notes for the Case Activities using Acumatica WebService.
Here is the code which I tried--
SP203010WS.Content content = context.GetSchema();
export = context.Export
(
new SP203010WS.Command[]
{
new SP203010WS.Value
{
LinkedCommand = content.Case.CaseID,
Value = currentCaseNo
},
content.Activities.Type,
content.Activities.Summary,
new SP203010WS.Field { FieldName="Body", ObjectName="Activities"},
content.Activities.StartDate,
content.Activities.CreatedBy,
new SP203010WS.Field { FieldName="NoteID", ObjectName="Activities"},
content.Activities.CreatedAt,
new SP203010WS.Field
{
FieldName = content.Activities.ServiceCommands.Attachment.FieldName,
Value = content.Activities.ServiceCommands.Attachment.Value,
LinkedCommand = content.Activities.ServiceCommands.Attachment
},
new SP203010WS.Attachment
{
FieldName = content.Activities.ServiceCommands.Attachment.FieldName,
Value = content.Activities.ServiceCommands.Attachment.Value
},
new SP203010WS.Value
{
FieldName = content.Activities.ServiceCommands.Attachment.FieldName,
Value = content.Activities.ServiceCommands.Attachment.Value,
LinkedCommand = content.Activities.ServiceCommands.Attachment
},
},
new SP203010WS.Filter[]
{
new SP203010WS.Filter
{
Field = content.Activities.StartDate,
Condition = SP203010WS.FilterCondition.Greater,
Value = maxStartDate
}
},
0, true, true
);
Check out the documentation for I200 (screen-based Web Services) pages 75-76. First, you have to get the list of file names, and then loop through each one to get the actual attachments.
Related
Thanks to #DChhapgar for help me figure out how to add "draft email" activity in opportunity, however, when I was trying to run my code I created following #DChhapgar instruction, I got error as follows:
Error #13: Inserting 'Activity' record raised one or more errors. Please review. Error: 'From' may not be empty
My code is as below:
CR304000Content CR304000 = context.CR304000GetSchema();
context.CR304000Clear();
//Email Activity Screen
CR306015Content CR306015 = context.CR306015GetSchema();
context.CR306015Clear();
//Locate Opportunity for which Email Draft needs to be added
CR304000Content[] CR304000result = context.CR304000Submit(
new Command[]
{
new Value { Value = opportunity.ID, LinkedCommand = CR304000.OpportunitySummary.OpportunityID},
//Invoke New Email Actity Action
CR304000.Actions.NewMailActivity
});
//Specify data for Email Activity
if (!string.IsNullOrWhiteSpace(email.Subject))
{
CR306015Content[] CR306015result = context.CR306015Submit(
new Command[]
{
new Value { Value = "abcd#efg.com", LinkedCommand = CR306015.Message.FromMailAccountID},
new Value { Value = email.ToAddress, LinkedCommand = CR306015.Message.To},
new Value { Value = email.Subject, LinkedCommand = CR306015.Message.Subject },
new Value { Value = email.Message, LinkedCommand = CR306015.Message_.ActivityDetails},
CR306015.Actions.Save,
});
}
I saw there were totally three fields related to email "from" in web service specification: CR306015.Message.FromMailAccountID, CR306015.Message.FromEmailAccountID, CR306015.Message.FromMailFrom, however neither of them worked for me.
Am I missing something?
I'm guessing FromMailAccountID needs to be an integer. Look at what the values are for existing records.
How to share login session between Acumatica Screen based API and the Contract based API?
Sharing session data between Contract-Based and Screen-Based API is supported in 5.30.1672 build onwards.
In below code snippet, we are logging in via Contract Based API, retrieving session cookie and using it in Screen Based API.
string sharedCookie;
var soapClient = new DefaultSoapClient();
using (new OperationContextScope(soapClient.InnerChannel))
{
soapClient.Login("admin", "123", null, null, null);
var responseMessageProperty = (HttpResponseMessageProperty)
OperationContext.Current.IncomingMessageProperties[HttpResponseMessageProperty.Name];
sharedCookie = responseMessageProperty.Headers.Get("Set-Cookie");
}
try
{
apitest.Screen context = new apitest.Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.Url = "http://localhost/AcumaticaCBWS/Soap/APITEST.asmx";
context.CookieContainer.SetCookies(new Uri(context.Url), sharedCookie);
SO301000Content salesOrdersSchema = context.SO301000GetSchema();
var commands = new Command[]
{
new Value
{
LinkedCommand = salesOrdersSchema.OrderSummary.OrderType,
Value = "SO"
},
salesOrdersSchema.OrderSummary.ServiceCommands.EveryOrderNbr,
salesOrdersSchema.OrderSummary.OrderType,
salesOrdersSchema.OrderSummary.OrderNbr,
salesOrdersSchema.OrderSummary.Description
};
var orders = context.SO301000Export(commands, null, 10, false, false);
}
finally
{
soapClient.Logout();
}
}
When I create a record (Case) using WebAPI, I need to get the created CaseCD. There is no return value it seems when using below method. Any Suggestion?
CR306000.Actions.Save
I haven't worked on Case in my project yet but have done something similar and would suggest you try below to get return value:
CR306000Content CR306000 = context.CR306000GetSchema();
CR306000Content[] CR306000Content = context.CR306000Submit
(
new Command[]
{
new Value {Value = "xxxxx", LinkedCommand = CR306000.CaseSummary.BusinessAccount},
new Value {Value = "xxxxx", LinkedCommand = CR306000.CaseSummary.Reason},
..............,
CR306000.Actions.Save,
CR306000.CaseSummary.CaseID
}
);
var CaseCD = CR306000Content[0].CaseSummary.CaseID.Value;
Using the latest version of Acumatica 5 with the latest and greatest updates, I’m running into a Web API issue that I have not been able to solve. I have code to execute the “Extend To Vendor” action on the Customer screen. It seems to run fine and does not error out but it fails to create the vendor. It seems to me that when performing the same actions through the website interface, the issue is that I’m not sending the correct command to choose the “Yes” button on the popup Warning box “Please confirm if you want to update current Vendor settings with the Vendor Class defaults. Original settings will be perserved otherwise.” I could be totally off though and any help would be greatly appreciated.
Here is my code:
String customerId = "SomeCustomerId";
String vendorClass = “SomeVendorClass”;
AcumaticaApiWS.AR303000Content AR303000 = context.AR303000GetSchema();
AcumaticaApiWS.AP303000Content AP303000 = context.AP303000GetSchema();
context.AR303000Clear();
AR303000.Actions.ExtendToVendor.Commit = true;
AcumaticaApiWS.AR303000Content[] AR303000result = context.AR303000Submit
(
new AcumaticaApiWS.Command[]
{
new AcumaticaApiWS.Value { Value = customerId, LinkedCommand = AR303000.CustomerSummary.CustomerID },
AR303000.Actions.ExtendToVendor
}
);
AcumaticaApiWS.AP303000Content[] AP303000result = context.AP303000Submit
(
new AcumaticaApiWS.Command[]
{
new AcumaticaApiWS.Value { Value = vendorClass, LinkedCommand = AP303000.GeneralInfoFinancialSettings.VendorClass },
new AcumaticaApiWS.Value { Value = "YES", LinkedCommand = AP303000.GeneralInfoFinancialSettings.ServiceCommands.DialogAnswer, Commit = true },
AP303000.Actions.Save
}
);
Thanks!
You're almost there. This is not an easy scenario since it involves multiple screens and dialogs, two things which are not trivial to use. The issues in your code sample are:
The dialog answer has to be set before the value. In your case, you're setting the vendor class first. This is counter-intuitive but the system has to know it before the dialog is displayed
The dialog answer is "Yes", and not "YES". You can see this by using the web browser inspector window and looking at the button title. The text is displayed in uppercase due to CSS styling.
You need to set the dialog answer on the primary view of the form (AP303000.VendorSummary.ServiceCommands.DialogAnswer), where the dialog is being displayed. There's no way to know this without looking at the source code, but I believe this is generally the case with dialog boxes.
The different Commit = true settings are not necessary (but don't hurt in this case).
This is the code I used, and in my case it extends a customer to a vendor and changes the vendor class at the same time:
String customerId = "ACTIVESTAF";
String vendorClass = "DATACENTER";
AcumaticaApiWS.AR303000Content AR303000 = context.AR303000GetSchema();
AcumaticaApiWS.AP303000Content AP303000 = context.AP303000GetSchema();
context.AR303000Clear();
AcumaticaApiWS.AR303000Content[] AR303000result = context.AR303000Submit
(
new AcumaticaApiWS.Command[]
{
new AcumaticaApiWS.Value { Value = customerId, LinkedCommand = AR303000.CustomerSummary.CustomerID },
AR303000.Actions.ExtendToVendor
}
);
AcumaticaApiWS.AP303000Content[] AP303000result = context.AP303000Submit
(
new AcumaticaApiWS.Command[]
{
new AcumaticaApiWS.Value { Value = "Yes", LinkedCommand = AP303000.VendorSummary.ServiceCommands.DialogAnswer },
new AcumaticaApiWS.Value { Value = vendorClass, LinkedCommand = AP303000.GeneralInfoFinancialSettings.VendorClass },
AP303000.Actions.Save
}
);
I'm new in CRM development. I know a basic thing like "best practice for crm 2011"
I wanna understand now how to work with lookup fields. And I think I chose the easiest way for my self.
I have an costum entity "contract" it has 5 more field, 2 of these are lookups.
First lookup (agl_contractId) - it is a link by it self
Second lookup (agl_ClientId) - link to Client.
What do I need?
When I choose fill First lookup (agl_contractId), script should find in this contract a Client and copy-past it to current form.
I've done script but it isn't work... (((
function GetAccountFromContract()
{
XrmServiceToolkit.Rest.Retrieve(Xrm.Page.getAttribute("agl_osnovnoy_dogovorid").getValue(),
'agl_osnovnoy_dogovoridSet',
null,null,
function (result) {
var Id = Xrm.Page.getAttribute("agl_osnovnoy_dogovorid").getValue();
if (result.Id != null) {
var LookupData = new Array();
var LookupItem = new Object();
var lookuptextvalue = lookupvalue[0].name;
var lookupid = lookupvalue[0].id;
var lokupType = lookupvalue[0].entityType;
alert(lookupvalue);
alert(lookupData);
Xrm.Page.getAttribute("agl_accountid").setValue(lookupData);
}
},
function (error) {
equal(true, false, error.message);
},
false
);
}
If I understand you well: When you select Contract in agl_osnovnoy_dogovorid field, you want to pull Client property from that Contract and put it in agl_accountid field?
If that is right:
First, get Id of selected Contract (from agl_osnovnoy_dogovorid field)
var selectedContract = new Array();
selectedContract = Xrm.Page.getAttribute("agl_osnovnoy_dogovorid").getValue();
{
var guidSelectedContract = selectedContract[0].id;
//var name = selectedContract[0].name;
//var entType = selectedContract[0].entityType;
}
Second, retrieve Client from agl_osnovnoy_dogovorid. Your oData query will be like:
http://crmserver/org/XRMServices/2011/OrganizationData.svc/ContractSet(guid'" + guidSelectedContract + "')/CustomerId
(In example I'm using CustomerId field. For your case enter Schema Name of Client field).
Now, execute query and put result into agl_accountid field:
$.getJSON(
Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc/ContractSet(guid'" + guidSelectedContract + "')/CustomerId",
function(data){
if(data.d.CustomerId != null && data.d.CustomerId.Id != null && data.d.CustomerId.Id != "undefined")
{
//set agl_accountid field
Xrm.Page.getAttribute("agl_accountid").setValue([{id:data.d.CustomerId.Id, name:data.d.CustomerId.Name, typename:data.d.CustomerId.LogicalName}]);
}
});
Your using REST to retrieve data but also using FetchXml example to setup the agl_accoutid lookup.
Also some of the conditions are not clear … anyway … I’ve incorporated the change to your original post.
function GetAccountFromContract()
{
var aodLookupValue = Xrm.Page.getAttribute("agl_osnovnoy_dogovorid").getValue();
if (!aodLookupValue) return;
XrmServiceToolkit.Rest.Retrieve( aodLookupValue[0].id ,
'agl_osnovnoy_dogovoridSet', null,null,
function (result) {
var customer = result.d["your attribute name"];
if (customer) {
var LookupData = new Array();
var LookupItem = new Object();
var lookuptextvalue = customer.Name;
var lookupid = customer.Id;
var lokupType = customer.LogicalName;
alert(lookupvalue);
alert(lookupData);
Xrm.Page.getAttribute("agl_accountid").setValue(lookupData);
}
},
function (error) {
equal(true, false, error.message);
}, false );
}