Hi,
I want to set the value of the field "currency" to dollar using javascript but it's not working
var id =Xrm.Page.data.entity.getId();
Xrm.Page.getAttribute('currency').setValue("Dollar");
alert(id);
*This post is locked for comments
Hi,
I want to set the value of the field "currency" to dollar using javascript but it's not working
var id =Xrm.Page.data.entity.getId();
Xrm.Page.getAttribute('currency').setValue("Dollar");
alert(id);
*This post is locked for comments
Hi Arci,
Open the following URL in your browser.
You will get the transactioncurrencyid of the currency name US dollar in that JSON response.
Hope this helps.
Hi,
How will I know the GUID of dollar?
Hi,
How will I get the GUID of Dollar?
Hi Arci,
You can also use below function
function SetLookUp(fieldName, fieldType, fieldId, value) {
try {
var object = new Array();
object[0] = new Object();
object[0].id = fieldId;
object[0].name = value;
object[0].entityType = fieldType;
Xrm.Page.getAttribute(fieldName).setValue(object);
Xrm.Page.getAttribute(fieldName).setSubmitMode("always");
}
catch (e) {
alert("Error in SetLookUp: fieldName = " + fieldName + " fieldType = " + fieldType + " fieldId = " + fieldId + " value = " + value + " error = " + e);
}
}
Thanks
Regards,
AW
Hi Arci,
In order to set the value of lookup field using javascript, use the code below.
var object = new Array(); object[0] = new Object(); object[0].id = "GUID of the currency record Dollar"; object[0].name = "Dollar"; object[0].entityType = "transactioncurrency"; Xrm.Page.getAttribute("currency").setValue(object);
Hope this helps.
Please note the SCurrencyId is GUID of Dollar
and sCurrencyName should be Dollar
Hi Arci,
Hope the following code would help.
The currency is a lookup field and you can't set it like a normal attribute value.
You should create a array in which you would create object and then set the parameters.
var Currency = new Array();
Currency[0] = new Object();
Currency[0].id = sCurrencyId;
Currency[0].entityType = "transactioncurrency";
Currency[0].name = sCurrencyName;
Xrm.Page.getAttribute("transactioncurrencyid").setValue(Currency);
Thanks
Phanidhar
The problem is that in this case, you need to send GUID as a parameter to the setValue method, not a string value.
You can get that GUID by opening currency lookup in the new window/tab and look for the GUID in URL
Example:
YOURORGANIZATION.crm4.dynamics.com/.../edit.aspx3F842377-5194-E611-80F5-5065F38A99D1%7d
GUID is marked in bold in the URL.
Hi
The currency field is of type Lookup. You need to assign the actual EntityReference of the Currency called "Dollar" in order for it to work the way you want.
Best way is to retrieve the currency instance using the webapi and then use the CurrencyId property for the lookup. You can read more about retrieving data through the webapi here: community.dynamics.com/.../ms-crm-2016-web-api-operations-retrieve-single-or-multiple-records
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,269 Super User 2024 Season 2
Martin Dráb 230,198 Most Valuable Professional
nmaenpaa 101,156