NetSuite - 使用Web服务错误关闭返回授权

时间:2015-09-17 17:56:52

标签: web-services netsuite

在NetSuite中尝试关闭退货授权订单项时,我收到以下错误消息:

  

INSUFFICIENT_PERMISSION   “由于以下原因之一,您无权为元素item.quantityreceived设置值:1)该字段为只读; 2)禁用相关功能; 3)该字段在记录时可用已创建或更新,但两种情况都不会。“

以下是代码:

                        //Pull down the RA in order to work with the line items in question
                        RecordRef rec = new RecordRef();
                        rec.internalId = internalId;
                        rec.type = RecordType.returnAuthorization;
                        rec.typeSpecified = true;

                        ReadResponse response = _service.get(rec);

                        //create the object from the response record returned
                        ReturnAuthorization ra = (ReturnAuthorization)response.record;

                        //cancel the order by updating the qty of each item to zero.
                        WriteResponse res = null;
                        ReturnAuthorizationItem[] raItemList = ra.itemList.item;

                        for (int lineCounter = 0; lineCounter < raItemList.Length; lineCounter++)
                        {
                            //only if the qty received is zero are we closing out the item(setting qty to zero)
                            if (raItemList[lineCounter].quantityReceived == 0)
                            {
                                raItemList[lineCounter].quantity = 0;
                                raItemList[lineCounter].quantitySpecified = true;
                            }
                        }

                        //create a new object and add all the changes in order to update the order lines
                        ReturnAuthorization updRa = new ReturnAuthorization();
                        updRa.internalId = internalId;

                        updRa.itemList = new ReturnAuthorizationItemList();
                        updRa.itemList.item = new ReturnAuthorizationItem[raItemList.Length];
                        updRa.itemList.item = raItemList;

                        res = _service.update(updRa);

我正在尝试将行数量更新为零,如果所有内容都已清零,这将影响返回授权。问题是如何更正此权限问题以运行此更新。我试过在同一个电话上设置其他字段。无论我尝试更新哪个字段,我都会收到相同的错误消息。这是在管理员帐户下运行,所有权限看起来都很好。事实上,我正在对SaleOrder对象运行这个相同的逻辑来关闭销售订单而没有任何问题。

非常感谢任何帮助。

谢谢, 比利

3 个答案:

答案 0 :(得分:2)

您无法直接编辑该订单项字段。该字段由Netsuite维护,并反映针对RA收到的项目收据。

如果要关闭RA而不接收只将行项目列字段“已关闭”设置为true。

答案 1 :(得分:0)

在仔细观察之后,这里有一个解决方案:

用以下代码替换循环中的if语句:

                                //only if the qty received and returned are zero do we close out the item(setting qty to zero)
                            if (raItemList[lineCounter].quantityReceived == 0 && raItemList[lineCounter].quantityBilled == 0)
                            {

                                raItemList[lineCounter].quantity = 0;
                                raItemList[lineCounter].quantitySpecified = true;
                                raItemList[lineCounter].isClosed = true;
                                raItemList[lineCounter].isClosedSpecified = true;

                                raItemList[lineCounter].quantityReceivedSpecified = false;
                                raItemList[lineCounter].quantityBilledSpecified = false;
                                raItemList[lineCounter].costEstimateSpecified = false;
                            }
                            else
                            {
                                raItemList[lineCounter].quantityReceivedSpecified = false;
                                raItemList[lineCounter].quantityBilledSpecified = false;
                                raItemList[lineCounter].costEstimateSpecified = false;
                            }

我猜我必须特定为false的字段是无法编辑的字段,因此需要从更新中删除它们。

答案 2 :(得分:0)

这是一个更好的样本。请注意评论重新排序

/Pull down the RA in order to work with the line items in question
RecordRef rec = new RecordRef();
rec.internalId = internalId;
rec.type = RecordType.returnAuthorization;
rec.typeSpecified = true;

ReadResponse response = _service.get(rec);

//create the object from the response record returned
ReturnAuthorization ra = (ReturnAuthorization)response.record;

//cancel the order by updating the qty of each item to zero.
WriteResponse res = null;
ReturnAuthorizationItem[] raItemList = ra.itemList.item;

ReturnAuthorization updRa = new ReturnAuthorization();
updRa.internalId = internalId;

updRa.itemList = new ReturnAuthorizationItemList();

ReturnAuthorizationItem[] updateItems = new ReturnAuthorizationItem[raItemList.Length];

for (int lineCounter = 0; lineCounter < raItemList.Length; lineCounter++)
{
    updateItems[lineCounter].line = raItemList[lineCounter].line; // you'll need to test this. Setting only the line should result in no changes to the RA line items that are not to be closed. use the &xml=T view before and after to make sure orderline (hidden) is still populated properly.
    //only if the qty received is zero are we closing out the item(setting qty to zero)
    if (raItemList[lineCounter].quantityReceived == 0)
    {
    updateItems[lineCounter].isClosed = true;
    // raItemList[lineCounter].quantitySpecified = true; // is quantitySpecified a field? it wasn't as of the 2012.2 endpoint
    }
}

//create a new object and add all the changes in order to update the order lines

updRa.itemList.item = updateItems;

res = _service.update(updRa);