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;
Related
I am implementing a custom HTML tag in GTM that should return certain values in the data layer. However, I’d like to encode one of the values as text.
I have a customer status variable that keeps track of how many orders a user has placed. I’d like to set up a JavaScript function that assigns a value of ‘New Customer’ when the customer status count = 0, and ‘Return Customer’ if the count is > 0.
Here is the code I have so far:
var returnCustomer = {{Shopify - Transaction - CustomerStatus}};
var returnStatus = returnCustomer(function(){
if (returnCustomer > 0) {
return 'Return Customer'
} else {
return 'New Customer'
}
});
I know this isn’t quite right-- anyone have ideas on how to solve this problem?
I won't comment in particular on your code (you call returnCustomer as a function - are you really sure {{Shopify - Transaction - CustomerStatus}} returns a function? Also your if clause does the opposite of what you describe in the text) because GTM has a built-in way to solve this without hand written code.
It's called a lookup table, and it allows you to return an output value depending on the value of an input variable.
Your requirement was:
I’d like to set up a JavaScript function that assigns a value of ‘New
Customer’ when the customer status count = 0, and ‘Return Customer’ if
the count is > 0.
So you have an input variable that's either 0 or 1, and you want to return a text output based on those values.
Go to Variables, New, and from the utilities sections chose "lookup table". I have named my Variable "My Output", you will probably use a better name.
Choose your input variable - I presume that's "{{Shopify - Transaction - CustomerStatus}}" in your case, I have named mine "My Input" for demonstration purposes.
Now click the "add row" buttons to add two rows. Each row will have two input fields.
Into the left hand side go the expected values from the input. Right hand side maps an output value to the input value.
Now, if "{{My Input}}" has a value of "0", "{{My Output}}" will assume a value of "New Customer". If it's "1", "{{My Output}}" will assume a value of "Return Customer". If it's neither, "{{My Output}}" will be undefined (you can set a default value, though).
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.
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
I have an AngularJS form that contains - among other fields - one of type url. The latter is important as this forces the corresponding input to be a valid URL.
Under certain conditions (for instance, a modal dialog with such a form is to be closed), I want to clear that form programmatically. For that purpose, I implemented method reset that basically clears the corresponding form model by setting $scope.formData = {}. Thus, it sets the form model to a new, blank object.
While that assignment clears all valid fields in the rendered HTML form, it does not clear invalid fields, like an invalid URL. For instance, if the user would provide invalid input ht://t/p as URL, that input would not be removed from the rendered form.
I think this is due to the fact that any invalid URL is not reflected by the model - such an invalid URL just wouldn't "make" it to the model because it does not pass validation in the NgModelController#$parsers array. Thus, in the model - there is no URL at all. Consequently, resetting the form model to {} cannot actually change the model's URL as it has not been set yet.
However, if method reset explicitly sets field $scope.formData.url = "", the invalid URL will be cleared properly (at least, the rendered form won't show it anymore). This is caused by the explicit change of the URL in the model. However, now, model variable formData.url contains the empty string (well, not surprisingly), while by using = {}, all fields would be undefined instead.
While assigning individual fields to "" works as workaround for simple forms, it quickly becomes cumbersome for more complex forms with many fields.
Thus, how could I programmatically reset the form efficiently and effectively - including all invalid input fields as well?
I created a Plunker at http://plnkr.co/c2Yhzs where you can examine and run a complete example showing the above effect.
Specify the type of your button as reset. That will not only call the ngClick function, it will also clear the content of the HTML form.
<button type="reset" ng-click="resetFormData()">Reset</button>
I think this solution is moderately elegant: your plnkr reviewed
The big difference is the initialization of your model object.
I think things gets messed up when a variable becomes undefined, it doesn't get updated anymore.. it should be connected (veeeery) deeply with how validation works (docs link)
Returning undefined in that case makes the model not get updated, i think this is exactly what happens behind the curtain
PS: you can recycle resetImplicitly for all your forms in the webapp :)
After trying several answers without success in similar questions, this worked for me.
In my controller:
$scope.cleanForm = function() {
$scope.myFormName.$rollbackViewValue();
};
Just call with some ng-click or any way you want.
Cheers
The Thing is tag is of type "url" which means
if user will enter specifically a valid url then only it will set values of model
If user will expicitly reset it which means setting model values to "" will again make textbox empty .
It is looking like it is setting the values but actually not ,so when you set its value to "" .Angular will set modal value to ""
Lets take another example : put replace "text" with "email"
<input type="email" ng-model="formData.name" />
<br />URL:
<input type="url" ng-model="formData.url" />
<br />
In above code If you will enter invalid email it will not set the values of email's model.
You probably need to make a copy of the model in its pristine state and set the model to pristine when you reset.
There's a good example here:
http://www.angularjshub.com/examples/forms/formreset/
The url form fields are passed into the model only if they are valid. Thus in case of an invlaid-url entry in the form, the scope variable is not assigned with the model and clearing the forms entry by assigning an empty object to the model will still persist the value at the UI front.
The best alternative to this is to assign the model associated with the form data with a null. A similar answer appears here:
https://stackoverflow.com/a/18874550/5065857
ng-click="formData={};"
just give like this ,
<button ng-click="formData={}">(1) Reset Full Data: formData = {}</button>
Reset your form data directly in ng-click itself.
I have a GridPanel with just two columns: names and commission percentages. The sum of all of the percentages should never exceed a predetermined maximum (say that 25% of the sale is up for grabs).
Name Commission
Bob 10%
Sally 15%
(Maximum is 25%)
Everything is fine.
I’ve attached a custom validator (see "validator") to the NumberField editor which works just great for complex logic on individual values, and I can sum up all of the values for the number column in the data store easily. But the problem is combining the two; the new value isn’t pushed to the store until after a successful validation, and the custom validator is only given the current value in question, with no context as to what row is involved (with which I could potentially subtract the old value, and use this new value in the total).
How can I get this validator to work in such a way that it makes sure that a newly entered value doesn’t push the sum over the maximum?
Name Commission
Bob 10%
Sally 16% (Invalid! Total commissions must not exceed 25%)
(Maximum is 25%)
You need to pull in the dirty value of the changed element before it is saved to the database. It does not make sense to validate the clean value after the fact.
See here for info on data storage in ExtJS:
http://www.fusioncube.net/index.php/managing-dirty-rows-in-a-sencha-extjs-editorgridpanel
You can use properties such as field.originalValue and field.getRawValue() to get at the data store and see the difference.
I didn’t quite use js1568’s answer, as I wanted to block bad values as they’re being entered; even before the AfterEdit event fires and the row gets marked dirty, and long before writing to the database. But that link did inspire me through its use of the grid’s selection model. So, my quick little solution:
Because the NumberField doesn’t pass any context to the custom validator (aside from the current value), using field.originalValue would have been awesome, but hey, life is hard.
But due to the fact that editing a row first requires selection of that row (and reinforced by the fact that this grid’s RowSelectionModel is set to SingleSelect), I know that the row being edited must be the only element in grid.selModel.selections.items[]. From there, it’s just a matter of
var newTotal = TotalCommissionPercentagesInGrid() – oldValue + newValue;
With oldValue being grid.selModel.selections.items[0].data.CommissionPercentage and newValue being the value passed to the validator function from the NumberField.
return ( newTotal <= percentageAvailable ) ? true : "No dice.";
Very nice.