Javascript and multiple form instances

I have an object called a product. There is a field called product price.

Now I have created 100 products. I want in SUM (mathematical operation) all the fields of the product “product price” to be displayed in another object called “field for all products”.

In addition, if I create 101 products, and this field is the "price of the goods", the "total price of the goods" in the opportunity will automatically automatically display the date.

So, I have SUMMED for form fields. for example, there is field A and field B, multiplying field A by 3.14 and displaying the result in field B.

Here is the code.

function SumField() { var price = Xrm.Page.getAttribute("new_price"); var total_price = Xrm.Page.getAttribute("new_total_price"); if(price.getValue() != null) { var newValue = price.getValue() * 3.14; total_price.setValue(newValue); // Make sure the changes are saved back to the server - in CRM 4.0, this was crmForm.new_fieldname.ForceSubmit = true; Xrm.Page.getAttribute("new_total_price").setSubmitMode("always"); } } 
+4
source share
2 answers

JavaScript will not work in this scenario, at least it will not be the optimal solution.

Instead of processing it using JavaScript, write a plugin that triggers changes to the Product object and updates the desired record of the feature object. (I believe that there will be few products related to one opportunity, that is, a 1: N ratio)

If you want this change in one product to update values ​​in all records. Ability to create another object, say, “Configuration”, which will hold this value and display it in the Opportunity form using JavaScript (reason: if updates to create one product all records about features will affect CRM performance)

+1
source

You have some options, the best choice depends on your technological expertise:

  • Workflow - starting a workflow when changing the new_total_price field and updating the related feature. For this you do not need any known programming languages.
  • Plugin - in updating your product object you can update the corresponding feature. You need to know C # or VB.NET.
  • Javascript One solution is to check whether the new_total_price populated with the product (for example, you are using FetchXML or OData) is filled with this information, you can update your feature.

There are more alternatives, but you have several options.

+1
source

Source: https://habr.com/ru/post/1469436/


All Articles