Hi,
I have created one custom service for creating partial Shipment of only picked quantity of sales order . I am passing Sales ID, Date of Shipment, and list of all item Ids in a concated string as a parameter to my service.
when I am calling this service inside my C# program, it was giving negative response. Packing slip was not getting created.
but same code when I am running inside Job by replacing all parameters with values. The code in running fine and creating packing slip for the order. please tell me what is mistake I was making while calling the service. My service code is as below
[AifCollectionTypeAttribute(‘return’, Types::String), SysEntryPointAttribute(true)]
public List createPackingSlip(SalesId _salesId,TransDate _transDate,ItemId _itemId)
{
List resultSet = new List(Types::String);
SalesFormLetter salesFormLetter;
SalesTable salesTable;
Query query;
QueryRun queryRun;
QueryBuildDataSource qbds;
QueryBuildRange Qbr;
;
try
{
query = new Query(QueryStr(SalesUpdatePackingSlip));
qbds = query.dataSourceTable(tableNum(SalesLine));
// Build query range to find those lines which needs to be posted.
qbds.addRange(fieldNum(SalesLine, SalesId)).value(queryValue(_salesId));
Qbr = Qbds.addRange(fieldNum(SalesLine, ItemId));
Qbr.value("’"+_itemId+"’");
queryRun = new queryRun(query);
salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
salesFormLetter.chooseLinesQuery(queryRun);
SalesFormLetter.update(SalesTable,_transDate, SalesUpdate::PickingList, AccountOrder::None, false, false);
resultSet.addEnd(‘true’);
}
Catch(Exception::CLRError)
{
resultSet.addEnd(‘false’);
}
return resultSet;
}
Thank you
Have you generated CIL? If you run your job, it executes X++, not CIL, so you may be running two different things.
Then use the debugger to see what exactly happens instead of just guessing.
By the way, returning the string value ‘false’ sounds like a bad idea. I would throw an exception instead and catch it in the calling code. That’s why we have exceptions after all, and WCF supports this scenario.
Hi Martin,
Thanks for your suggestion. Actually I was confident that you are the person who will defiantly reply for my query.
I did Full CIL after creation of my service, still its not working and I made changes and now I am throwing exceptions instead of just returning false. And I was getting “Unable to cast object of type ‘Dynamics.Ax.Application.QueryRun’ to type ‘Dynamics.Ax.Application.SysQueryRun’.” This exception. Can you help me to solve this Error.
Thank you
Hi Martin,
This is your one of post which is related to my query. I am doing same functionality with SalesFormLetter Class. I am not getting how to cast Query to SysQuery for using it with (.chooselinesquery()).
Thank you
Let me give you an example:
QueryRun qr = new QueryRun(new Query(queryStr(Vend)));
SysQueryRun sqr = qr;
I’m assigning QueryRun object to SysQueryRun variable, which is acceptable in X++, but not in normal object-oriented languages including CIL.
This would be correct:
QueryRun qr = new SysQueryRun(new Query(queryStr(Vend)));
SysQueryRun sqr = qr as SysQueryRun ;
Notice that you still can use the variable of QueryRun type if required, but we’re assigning an instance of the subtype that we’ll need later.
Martin,
Thank you very much. it did solved my problem and now my service is working fine…
regards,
Sumit