Get text values from Global picklist in CRM Online 2013? - javascript

How can I extract values from Global picklist in crm 2013? I update some text fields based on the value of the option set. Usually in local option set we can use the following code to update the fields based on the value of option set.
var value = Xrm.Page.getAttribute("new_optionset").getText();
if(value=="ABC"){
Xrm.Page.getAttribute("new_field1").setValue("Value");
Xrm.Page.getAttribute("new_field2").setValue("Some Value");
Xrm.Page.getAttribute("new_field3").setValue("Some Other Value");
}
But this does not seem to work if I am using a global option set. Is there another way of handling them?

From JavaScript there is no difference how to get the text between a local and a global optionset.
The syntax is the one you already know:
var value = Xrm.Page.getAttribute("new_optionset").getText();
If you want a library to manage the optionsets you can check this one I wrote:
http://gallery.technet.microsoft.com/scriptcenter/OptionSet-JavaScript-76af41f5

Related

Setting and accessing document-level variables in Acrobat 10 Pro

I have a form that currently functions based on in-field calculations. In order to get some of the calculations to work, I had to create hidden calculated fields and then calculate off of the those hidden fields to get other calculations.
(This is a loan application form, so there are many variables, such as credit score, interest rate based off credit score, loan term, etc.)
I want to move the hidden fields to document-level variables, but can't seem to make the other fields recognize the document-level variables, or calculate based on their (supposed) values.
For example, I have a field that is populated by a series of checkboxes. Right now, the MouseUp Event Action populates the htxtLoanType using the following script:
this.getField("htxt_LoanType").value = "0";
This and 2 other similar functions create the 3 values I need to access an array containing all the possible interest rate combinations, based on credit score, loan term and loan type.
I have tried to enter a variable (outside of a function) into the Document JavaScripts named "Variables" here...
var vLoanType; // The array value of the current loan type...
I then try to set the value of 'vLoanType' with this script linked to the MouseUp EventScript of the checkbox:
//this.getField("htxt_LoanRequestType").value = "0";
vLoanType = "0";
The commented section works, since it assigns the value directly to the textfield. The vLoanType = "0"; doesn't seem to assign anything to the variable, since I can't get the variable to return a value to a text field.
If I try to enter
event.value = vLoanType;
into a text field's custom calculation script, it does nothing. It doesn't return the variable's value, which should be set to "0", and it doesn't display anything.
What am I missing regarding the setting and returning of document-level variables? I don't code professionally, so any help would be appreciated. Also, let me know if you need more information.
Variables declared outside of a function in a document level script (which is not the default when you create a new document level script) are scoped to the PDF document which means that any field can access them. By default, creating a new document level script via Acrobat Pro will create a stub function for you based on the name you entered in the dialog. Delete the function; it's not necessary.
To display a variable's value in a text field, use the following code where "foo" is the variable name and "myField" is the name of the field in question.
this.getField("myField").value = foo;

What does 'data()' do in '$("#myWidget").data(`ejTE`)'

This works:
var editor = $("#htmlEditor").data('ejRTE');
The question is what does .data('ejRTE') do?
It retrieves the widget which is part of this html:
<textarea id="htmlEditor" value.bind="entity.content"
ej-rte="e-width:100%"
ref="textArea"
style="height: 220px"></textarea>
How do I retrieve it without jQuery.
jQuery.data() Store arbitrary data associated with the specified element and/or
return the value that was set.
So basically the widget stores some data in the element htmlEditor indexed ejRTE, I bet it is a custom object used by this tool.
var editor = $("#htmlEditor").data('ejRTE');
then editor will hold the object stored by the widget for this element
If you set data like this $(#myWidget).data('foo', 'myFoo') then jQuery will create an object called 'jQuery224059863907884721222' on myWidget which it uses to store the value.
I am guessing that the number is an arbitrary datetime value.
I stepped through the jQuery code, and it's not practical to replace it. I thought it might be just a line or two of code.

How to know if field is masked due to field level security?

is there a way to find out if field level security has been applied to a field in DCRM 2013?
I'm looking for something like:
Xrm.Page.getControl("controlName").isMasked()
You can use Xrm.Page.getAttribute("attributeName").getUserPrivilege(), which returns an object containing three booleans:
canRead
canUpdate
canCreate
In your case you could check the value of .canRead to figure out whether the user can see the contents of the field or not.

Dynamically set value in category.ftl

I have a form in share with multiple fields using category.ftl. I want to set default values in those fields dynamically. I can set default value by passing static path of category in share-config-custom.xml. But now my requirement is to read values stored in one file and than set those values as default in category.ftl.
For ex, On above screenshot I have set default language as English by passing English reference statically in share-config. So every time when a form renders it sets English as default language. I want this to be changed to set default language to value which is stored in file. So how to pass dynamic reference of category in share-config-custom.xml file?
Any help would be greatly appreciated!!!
You cant configure dynamic things in share-config-custom.xml.For that you need to workj on below things.
For each and every picker in alfresco ,alfresco share is using below javascript file.(This are YUI scripts)
1.generic-object-finder.js
2.object-finder.js
object-finder.js = >
This file is generally used when type of content is authority(users of alfresco).So i think this will be not used in your case.
generic-object-finder.js = >
This file is used for generic picker and using this you can set default values.
======================================================================
Below are steps to set value in picker.
1.Alfresco.util.ComponentManager.list("Alfresco.GenericObjectFinder")
Above method will return all object of picker , We need to pick one by one and set default value one by one in alfresco advanced search.It will return object in array form
2. X.options.defaultValue need to be set.
Where X will first element of Alfresco.util.ComponentManager.list("Alfresco.GenericObjectFinder") array
3.x.selectItems("workspace://SpacesStore/f73a4de7-7a45-412d-ac7d-56061fcf9d76")
Above will set default value.You must need to pass relevant value here.

How can I bind the selected text of a Select box to an object's attribute with Knockout JS, or anything else?

I have a select box pull down that I'm populating with a JSON list returned from a stored procedure, but unfortunately when I update the linked object I need to return the selected text of the pulldown, not the selected index like one would think (poor database design, but I'm stuck with it for now and cannot change it).
Does anyone have any ideas what I can do to keep the selected text synced with the appropriate javascript object's attribute?
You could keep both, the value and the text, if you use subscribers.
For instance, if each of your javascript objects look like this:
var optionObject = {
text:"text1"
value: 1
}
Then your binding would look like:
Where 'OptionsObjects' is a collection of optionObject and selectedOption
has two observable properties: text and value.
Finally you subscribe to the value property of the selectedOption:
viewModel.selectedOption.value.subscribe(function(newValue){
var optionText = viewModel.OptionsObjects[newValue].text;
viewModel.selectedOption.text(optionText);
});
Then if you want to see the new selected option text when the value is changed,
you could have a binding as follows:
<span data-bind:"text:selectedOption.text"></span>
In your particular case you would return selectedOption.text().
So yes, you got what I was getting at. Use the text as the value for the select options rather than using an index. The value really should be something useful, I can't think of any case where I've ever used an index. A number sure, but a number that relates to the application's models in some way (like an id from a database), not to the number of items in the select box.
Well done.

Categories

Resources