2016-06-15 3 views
0

계약 레코드의 필드를 PO 레코드에서 변경하는 userevent 스크립트가 있습니다. 스크립트가 제대로 실행 중입니다. 그러나 계약서 레코드를 편집하고 제출하려고 할 때마다 : "다른 사용자가 편집을 시작한이 레코드를 업데이트했습니다. 레코드를 닫고 다시 열어 변경 사항을 저장하십시오."라는 오류가 발생합니다.Netsuite Userevent Script

이유가 무엇인지 알고 계십니까?

/*--------------------------------------------------------------------------------------------------------------- 

Description  : Whenever the PO vendor is changed(due to Split vendor) that should replace the same in Contract page record automatically. 
Script type   : User Event Script 
Script id   : customscript452 
Version    : 1.0 
Applied to   : Contract 
----------------------------------------------------------------------------------------------------------------*/ 

function srchfield() 
    { 
     var stRecordid = nlapiGetRecordId(); //returns the contract id 
     if(stRecordid== undefined || stRecordid== null || stRecordid==' ') 
      { 

      } 
       else 
       { 
        var stRecordtype = nlapiGetRecordType(); //returns the contract record type = jobs 

        var stRecord = nlapiLoadRecord(nlapiGetRecordType(), stRecordid); 
        nlapiLogExecution('debug','Load Object',stRecord); 

        var stContractID = stRecord.getFieldValue('entityid'); //returns the value of the field contractid whose fieldid is = entityid 
        nlapiLogExecution('debug','stContractID',stContractID); 

        var stCompanyName = stRecord.getFieldValue('companyname'); //returns the value of the field company name whose fieldid is = companyname 
        nlapiLogExecution('debug','stCompanyName',stCompanyName); 

        var stConcatenate = stContractID+" : "+stCompanyName; //Concatenate the two Fields to get the result which needs to be found in PO 

        var arrFilters = new Array(); // This is Array Filters all the Purchase Order Record Search 
        arrFilters.push(new nlobjSearchFilter('type', null, 'anyof', 
         [ 
          'PurchOrd' 
         ])); 
        arrFilters.push(new nlobjSearchFilter('mainline', null, 'is', 'T')); //This is to exclude line level results 
        arrFilters.push(new nlobjSearchFilter('custbodycontract', null, 'is', stRecordid)); //This is Filters in Contracts Search 

        var arrColumns = new Array(); 
        arrColumns.push(new nlobjSearchColumn('entity')); //This is Search Column Field in Records 
        var arrSearchresults = nlapiSearchRecord('purchaseorder', null, arrFilters, arrColumns); //This is Filters in Search Result Purchase Order 

        if(arrSearchresults== undefined || arrSearchresults== null || arrSearchresults==' ') 
         { 

         } 
          else 
          { 
           var length = arrSearchresults.length; 
          } 

        if(length== undefined || length== null || length==' ') 
         { 

         } 
          else 
           { 
            for (var i = 0; arrSearchresults != null && i < arrSearchresults.length; i++) 
             { 
              var objResult = arrSearchresults[i]; 
              var stRecId = objResult.getId(); 
              var stRecType = objResult.getRecordType(); 
              var stCntrctName = objResult.getValue('entity'); //This is Value are Get Purchase Order Records and Field for Vendor = entity 
             } 
           } 
        //var record = nlapiLoadRecord(nlapiGetRecordType(), stRecordid, stCntrctName); 

        if (stCntrctName =='custentityranking_vendor_name') 
         { 

         } 
          else 
           { 
            var stChangeName = stRecord.setFieldValue('custentityranking_vendor_name', stCntrctName); //This is Value are the Set in Main Vendor Field = custentityranking_vendor_name 

            nlapiSubmitRecord(stRecord, null, null); // Submit the Field Value in Record Type 

           } 
       } 
    } 

답변

1

사용자 레코드 스크립트는 계약 레코드가 데이터베이스에 저장 될 때 실행됩니다. 동시에 데이터베이스에서 레코드의 두 번째 복사본을로드하고 복사본도 제출하려고합니다. 이로 인해보고있는 오류가 발생했습니다.

nlapiSetFieldValue을 사용하여 계약서의 해당 필드를 설정하면됩니다.

JavaScript Guide over at MDN을 통해 JavaScript에 익숙해지는 것이 좋습니다. 특히 Boolean description을 살펴보고 JavaScript가 부울 표현식을 평가하는 방법을 알고 있어야합니다. 이렇게하면 많은 조건문이 필요하지 않으므로 여기서 작성한 코드의 양을 크게 줄일 수 있습니다.

0

어떤 유료 서비스가 있습니까? 사용중인 사용자 이벤트 및 API의 유형에 따라 상황이 바뀌고 있습니다. 코드를 살펴보면 데이터베이스에서 이미 업데이트 된 계약 레코드를로드하려고합니다. 따라서 아래에서 귀하의 문제를 해결할 수 있습니다. 희망, 도움이됩니다.

제출 전이라면 스크립트가 배포 된 위치에서 레코드를로드 할 필요가 없습니다.
nlapiGet * 및 nlapiSet *을 사용하여 값을 가져오고 설정하십시오. 또한 변경 사항을 반영하기 위해 nlapiSubmitRecord를 사용할 필요가 없습니다. 제출하기 전에 레코드가 데이터베이스에 저장되기 전에 실행됩니다. 따라서 변경 사항이 반영됩니다.
그런 다음 제출 한 후에 레코드가 데이터베이스에 저장된 후에 실행되므로 필요에 따라 다음 API를 사용할 수 있습니다. 실제로이 방법이 솔루션을 확인하는 가장 좋은 방법입니다.

  • nlapiGetNewRecord - 스크립트는 헤더와 하위 목록에서 정보를 검색 할 필요가있는 경우에만 사용합니다. 그리고 아무것도 설정할 수 없습니다.
  • nlapiLookupField - 스크립트가 헤더에서 값을 가져오고 라인에서 아무것도 가져 오지 않으면이 옵션을 사용하십시오.
  • nlapiSubmitField - 헤더에서만 변경되는 경우 스크립트가로드 및 제출할 필요가 없습니다. 이 API 만 사용하십시오.
  • nlapiLoadRecord 및 nlapiSubmitRecord- 스크립트가 줄에서 변경 사항을 갖고 데이터베이스에서 커밋하기 위해 후자의 API를 사용하는 경우 전자를 사용하십시오.
0

사용자 이벤트 스크립트 코드이므로, 성능을 고려한 코드는 좋지 않습니다. 여기

VAR stRecordid = nlapiGetRecordId() 병합 할 수있는 샘플입니다; // 계약 ID를 반환합니다.

// Every record has an internal id associated with it. No need to add condition explicitly to check if its null 
var stRecordtype = nlapiGetRecordType(); 

var fields = ['entityid','companyname']; 
var columns = nlapiLookupField(stRecordtype, stRecordid, fields); 

var stContractID = columns.entityid; 
var stCompanyName = columns.companyname; 

nlapiLogExecution('debug','stContractID/stCompanyName',stContractID+'/'+stCompanyName); 

var stConcatenate = stContractID+" : "+stCompanyName; //Concatenate the two Fields to get the result which needs to be found in PO 
// 
//your code of search 
//you can improve that code also by using nlapilook up 

nlapiSubmitField(stRecordtype, stRecordid, 'custentityranking_vendor_name', 'name to be updated');