[英]Javascript and multiple instances of a form
I have an entity called product. 我有一个称为产品的实体。 There is a field called item price.
有一个称为项目价格的字段。
Now i have created 100 products. 现在我已经创建了100个产品。 I want to SUM (mathematical operation) all the products "item price" field and display it in an other entity called opportunity field called "total items price".
我想对所有产品的“项目价格”字段进行SUM(数学运算),并在另一个称为“项目总价格”的机会字段中显示它。
Besides this if i create 101 product and it's "item price", "total items price" field in opportunity automatically up date itself. 除此之外,如果我创建101产品,并且机会中的“项目价格”,“项目总价格”字段本身会自动更新。
So for i have SUMMED to fields of a form. 因此,对于我来说,求和到表单的字段。 eg there is a field A and field B, multiplying field A with 3.14 and displaying result in field B.
例如,存在一个字段A和字段B,将字段A与3.14相乘并在字段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");
}
}
JavaScript will not work in this scenario, atleast it will not be the most optimum solution. JavaScript在这种情况下将不起作用,至少它不是最佳解决方案。
Rather than handling it with JavaScript write a Plugin that fires on change in Product entity and updates the desired record of opportunity entity. 与其使用JavaScript进行处理,不如编写一个插件,该插件在产品实体的更改时触发并更新所需的机会实体记录。 (I am considering that there will be few products related to one opportunity ie 1:N relationship)
(我正在考虑与一种机会相关的产品很少,即1:N关系)
In case you want that change in one product will update values in all records Opportunity create a another entity say "Configuration" which will hold this value and show it on Opportunity form using JavaScript (reason being: If one product record creation updates all records of Opportunities it will impact performance of CRM) 如果您希望一个产品中的更改将更新所有记录中的值,则商机将创建另一个实体,例如“配置”,该实体将保存此值并使用JavaScript在“商机”表单上显示它(原因是:如果一个产品记录创建会更新以下所有记录,机会将影响CRM的绩效)
You have some possibilities, the best choice depends of your technology expertise: 您有一些可能性,最佳选择取决于您的技术专长:
There is more alternatives but you have here some options. 还有更多选择,但您这里有一些选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.