How to differentiate manual save and programmatic save in CRM 2011 JScript - javascript

I have a Javascript code registered onSave of record. I need to check whether the save operation is happening by clicking on Save button or saving programmatically like Xrm.Page.data.entity.save().
Do we have a JScript code to get the source control of the event, means event generator?

Without this information on the context why not set a variable in the JavaScript function where you call entity.save explicitly? You can then check this from any other JavaScript function to determine "context". It's a bit of a hacky global flag but it'll do the job.
If you need to get a hold of this "context" within a plugin you can create a hidden attribute on the form setting submitMode('always') that you set prior to save within the custom JavaScript and reset on load.

Have you tried something like that: https://community.dynamics.com/product/crm/f/117/t/58773.aspx

Related

Dynamics crm opening assign window

In a javascript function, I want to open the window that is usually opened when the user clicks on the "Assign" button in the lead form.
In the ribbon workbench, I see that the function that is called on the click of Assign is XrmCore.Commands.Assign.assignObjectLegacy, in the library Main_system_library.js.
Is it possible to call this function in javascript?
Doing such things like using internal libraries, calling internal methods are unsupported in Dynamics CRM. Future version of product changes may affect this implementation.
Instead, try to use jQuery to find the button element & invoke the onclick event like $('#assignbuttonid').click(). This is too unsupported because we cannot use DOM manipulation but somewhat ok.
Otherwise I don’t see any alternate supported solution to do this.
Using jQuery is one way to mimic the feature but like Arun said it's unsupported and risk to break in the next update. Instead, I would call a custom action. An action is basically a workflow. You can assign your entity via javascript and it will be supported.
Here is a sample you can use: https://community.dynamics.com/crm/b/nishantranaweblog/archive/2017/05/27/sample-code-to-call-action-using-web-api-in-crm

Jquery detect textbox programmatic change

Long story short I am cowboying some code in which a custom framework I am using allows me to insert a script to manipulate the page to do what I want.
I want to fire a function, but only after the textbox I want to use has been populated from the webservice that gets called.
In Jquery/Javascript is there anyway to call a function like the jquery change function, but one that can detect when the textbox has been changed from javascript, and not by the user in the browser.
I currently just have:
$("#mytexbox").on('input propertychange paste change',function() {
doSomething();
});
But this does not fire when the original function in locked code sets the value of the textbox.
Note: I can not just overload the original function as most of it is built up from dynamic server side code that I can't mimic in Javascript.
I also want to avoid having to use setTimeout() as this is unreliable and not really a nice solution.
Thanks in advance!
Maybe you can use a hidden div or input and check the changes on this instead of changes on #mytextbox. Obviously, the user can not change the hidden div, but the script can. You get the trick? ;)

Can I track changes to a web form using webtrends?

Does anyone know of a way to track changes to a web form, i.e. select or text field using webtrends?
I know Google Analytics has similar functionality, can this be done in WebTrends?
Webtrends has Javascript click tracking so you'd have to add Javascript onChange or onClick events to whatever you need to track.
Since web forms don't typically trigger the Webtrends link tracking, you have to use the dcsMultiTrack function, passing the variables that need to be tracked.
For example, you might use the following to track the URL that you're on and the fact that a particular field was clicked:
onClick="onclick="dcsMultiTrack('DCS.dcssip','www.domain.com','DCS.dcsuri','/yourpage', 'WT.ti','formfield1','WT.dl','1');"
Note that the WT.dl parameter should be set so you don't count extra page views. Also note that the WT.ti parameter is used for automatically tracking this as a link click. If you need more granularity, you can always define another variable (for example, "formname) and configure Webtrends to report on that as another dimension.

Setting the textbox to read only on submit

Can anyone suggest me a javascript function to set the text box to readonly on pressing the submit button. So that the contents cannot be modified.
To disable an input you'll want to set its disabled attribute. If you can use jQuery then something like this would be what you're looking for:
$('#idOfYourInput').attr('disabled', true);
If jQuery isn't an option, then you'll want to use the setAttribute function. Take a look at the MDN documentation for it. Something like this:
var d = document.getElementById('idOfYourInput');
d.setAttribute('disabled', 'true');
(Both of these code samples assume that you're identifying your input by its id attribute. If that's not the case, these would need to change. The jQuery one would be trivial to change, you'd just need to update your selector to identify the target attribute. The latter code sample would need to use some other DOM navigation/selection functions to find your input element.)
You'd want to include this within the handler for your submit button. Understand, however, that this will only matter on the current context of the page. So I'm assuming your submit button is being used to perform a submit via AJAX and not actually POST the whole page, correct? Because if you're POSTing the whole page then, when the page refreshes, you'll be on an entirely new page context. (Which means any code associated with a button click event will not yet have run.)

Why does this javascript throw an undefined error?

I'd like to define my own onblur event for all text boxes in an application so that I can strip all high ascii values, so I wrote a script that runs on an asp.net master page that runs per page load, overriding all text box / area onblur events, and storing a copy of the old event.
The new event then called the old event so it wouldn't break existing events across the forms.
It worked fine until a page defined an onblur like: onblur="func(this)"
When the original event fires the 'this' point doesn't seem to point to the sender control any longer.
Pastebin link with 2 simple examples
So would anyone be able to point me towards a better way to accomplish this?
Thanks!
To call a function dynamically while controlling the value of this, use func.apply instead of a standard call. For example instead of
myStoredFunc(arg1, arg2)
use :
myStoredFunc.apply(this, arguments);
This way the value of the this variable will be correctly passed to the called function, thanks to apply's first argument. The second argument allows you to specify the parameter values (here I pass all the current function's arguments to the called function).

Categories

Resources