2014-11-27 3 views
0

누구나 견적 제품 양식의 레코드 값을 업데이트하는 플러그인을 만들려고 했습니까? 확장 금액 필드를 계산하는 사용자 지정 수식이 필요하기 때문에 하나를 만들었지 만 CRM에서이 필드를 채우는 자동 계산이 있습니다. 이것은 계산 공식을 전혀 업데이트하지 못하게합니다. 내 플러그인이 무엇CRM 2013 견적 제품 업데이트 섹션

은 다음과 같습니다

  1. 가 (사용자 정의 필드) 단위, 수량 및 할인 % 당 필드 가격의 값을 가져옵니다;
  2. 필요한 값을 계산합니다.
  3. 확장 금액 필드에 설정합니다.

그러나 "비즈니스 프로세스 오류"가 발생하기 때문에이 중 아무 것도 작동하지 않습니다. 기본적으로이 오류는 레코드의 GUID를 사용하여 액세스 할 수 없음을 알려줍니다. 해당 필드 사용/그들을 설정에 액세스 할 수있는 방법이 있는지

protected void ExecutePostQuoteProductUpdate(LocalPluginContext localContext) 
    { 
     if (localContext == null) 
     { 
      throw new ArgumentNullException("localContext"); 
     } 

     IPluginExecutionContext context = localContext.PluginExecutionContext; 
     IOrganizationService service = localContext.OrganizationService; 

     Guid quoteProductID = (Guid)((Entity)context.InputParameters["Target"]).Id; 
     ColumnSet set = new ColumnSet(); 
     set.AllColumns = true; 

     var quote = service.Retrieve("quotedetail", quoteProductID, set); 
     var priceperunit = quote.Attributes["priceperunit"]; 
     var teamleader = quote.Attributes["new_disc"]; 
     var manualdiscountamount = quote.Attributes["manualdiscountamount"]; 
     var volumediscountamount = quote.Attributes["volumediscountamount"]; 
     var VAT = (int)quote.Attributes["new_vat"]; 

     var discountamount = (double)priceperunit * (double)teamleader/100; 
     var baseamount = (double)priceperunit - discountamount; 
     var tax = baseamount * VAT/100; 
     var extendedamount = baseamount + tax; 
     quote.Attributes["new_discountamount"] = discountamount; 
     quote.Attributes["baseamount"] = baseamount; 
     quote.Attributes["tax"] = tax; 
     quote["description"] = priceperunit; 
     quote.Attributes["extendedamount"] = extendedamount; 
     service.Update(quote); 


    } 

, 알려주세요 :

여기 내 코드입니다.

미리 감사드립니다. :/

답변

0

extendedamount을 직접 업데이트 할 수 없습니다. 자동으로 계산되는 기본 제공 입력란을 사용하는 경우 대신 CRM이이를 처리합니다.

필드는 baseamount, quantity, discountamounttax입니다.

사용자 정의 계산으로
quote.Attributes["baseamount"] = new Money(baseamount); // Money and decimal numbers use the "decimal" datatype and not double. 

, 당신은 실제 양에 사용자 정의 필드에 저장 비율을 변환하고 discountamount 속성에 할당해야합니다 당신은 그들을 저장해야합니다, 그래서 이들은 Money 필드입니다 . 뭔가 같은 : tax은 할인을 반영하기 위해 다시 계산해야 할 수도 있습니다,하지만 프로세스가 정확히 같은 일을해야

var discountamount = (decimal)priceperunit * (decimal)teamleader/100; 
// Assigning the actual discount amount will automatically recalculate the extended amount on the line. 
// No need to recalculate all fields. 
quote.Attributes["discountamount"] = new Money(discountamount); 

참고.

+0

감사합니다. 제이슨! 나는 이제 Extended Amount를 특정 값으로 설정하기 위해 다른 필드를 사용해야한다는 것을 알고 있습니다. 이렇게하면 priceperunit와 같은 필드에 어떻게 액세스 할 수 있습니까? var priceperunit = quote.Attributes [ "priceperunit"]; 은 CRM에서 ISV 오류를 제공합니다./ – Goshenko

+0

"priceperunit"속성은 GUI (또는 특히 델타 변경)에 의해 업데이트 된 경우에만 가져 오며, 그렇지 않으면이를 가져와야합니다 이미지의 일부입니다. 'baseamount'와'quantity'를 안다면 간단히'price = baseamount/quantity'를 할 수 있습니다. –

+0

그건 좋은 해결 방법이지만, 불행히도 ** baseamount **에 접근 할 수는 없습니다. – Goshenko

관련 문제