locked
Refer to textbox on html webresource RRS feed

  • Question

  • I want to read a value from a textbox on a webresource, google is not my friend with this as I am struggling to refer to it.

    I have an entity form "Project Relationship, within this form I have embeded a HTML webresource "WebResource_txtbox" in this webresource I have a txtbox named "SrcCriteria".

    I just can't get my head around how to retrieve the value in this webresource to pass it to a field on the main form.

    regards,

    Matt

    Monday, August 11, 2014 3:11 PM

Answers

  • You can add jquery library from the url.

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>


    Polat Aydın Crm Software Developer

    • Marked as answer by Matt_Hirst_UK Wednesday, August 27, 2014 3:20 PM
    Wednesday, August 27, 2014 2:53 PM

All replies

  • So you're going to want to start here: http://msdn.microsoft.com/en-us/library/gg328034.aspx

    That will get you info on how to access a web resource on the form.  From there, you're going to have to scrape the HTML in whatever manner you prefer.  There's nothing special in Dynamics CRM that shortcuts that for you that I'm aware of. 


    The postings on this site are solely my own and do not represent or constitute Hitachi Solutions' positions, views, strategies or opinions.

    Monday, August 11, 2014 9:14 PM
  • Am struggling with this, as everything I try seems to fail miserably.

    I have tried:

    to set the value

    Xrm.Page.getAttribute('SrcCriteria').setValue('fgrhr');

    to get values

    Xrm.Page.getAttribute('SrcCriteria').getValue();

    and these generally fail with Unable to get property 'setValue' of undefined or null reference which I assume means I ma not referencing the field correctly.

    so as I say am struggling with this.

    Matt

    Friday, August 15, 2014 12:55 PM
  • Can you add your html file to this.

    <script type="text/javascript" src="../../../../../../webresources/ClientGlobalContext.js.aspx"></script>

    And you are in subgrid so you have to get window.parent. Here the code below

    window.parent.Xrm.Page.getAttribute('SrcCriteria').setValue('fgrhr');


    Polat Aydın Crm Software Developer



    Friday, August 15, 2014 1:20 PM
  • If I try, window.parent.Xrm.Page.getAttribute('SrcCriteria').setValue('fgrhr');, all I get is an error saying:

    Object doesn't support property or method 'getAttribute'.

    regards,

    Matt

    Friday, August 15, 2014 3:24 PM
  • I got the same error message.
    Saturday, August 16, 2014 2:19 PM
  • Oh good at least I am happy to know it is not just me.

    regards,

    Matt

    Monday, August 18, 2014 8:27 AM
  • Did you add this tag into your custom html web resource?

    <script type="text/javascript" src="../../../../../../webresources/ClientGlobalContext.js.aspx"></script>

    Here is an example of custom html web resource as Subgrid in Quote Entity. You can see below , debuging code.


    Polat Aydın Crm Software Developer



    Friday, August 22, 2014 1:39 PM
  • I have added that and ever since doing so when I publish the code I seem to get spurious <SCRIPT> lines added to the file:

    <SCRIPT type=text/javascript src="/ATest/_common/global.ashx?ver=141881304"></SCRIPT>
    
    <SCRIPT type=text/javascript src="/ATest/_common/windowinformation/windowinformation.js.aspx?lcid=1033&amp;ver=141881304"></SCRIPT>
    
    <SCRIPT type=text/javascript src="/ATest/_common/entityproperties/entitypropertiesutil.js.aspx?tstamp=-614233227&amp;ver=141881304"></SCRIPT>
    

    The ATest refer to a server but I am not on that I am on AQA.  Any ideas?  Also these three lines get repeated over and over again.

        function btn_Press()
            {
                alert("Pressed Button");
                alert(window.parent.Xrm.Page.getAttribute('SrcCriteria').getValue());
            }
    
            </SCRIPT>
    
    <META charset=utf-8></HEAD>
    <BODY onload=retrieveCustomerTelephone() contentEditable=true><INPUT id=SrcCriteria maxLength=20 name=SrcCriteria></INPUT> <INPUT onclick=btn_Press(); id=btn_Src type=button value=Search> </SCRIPT>
    

    With the above code when the button is pressed the alert pops up for "Pressed Button" but the second alert does not appear.

    regards,

    Matt

    Tuesday, August 26, 2014 2:03 PM
  • Can now access the textbox with:

    alert(document.getElementById('SrcCriteria').value);

    To set value:

                var textcontrol = document.getElementById("SrcCriteria");
                textcontrol.value = "Some text";

    Just don't understand why I keep getting all of the additional lines below.

    regards,

    Matt



    Tuesday, August 26, 2014 2:28 PM
  • Did you try my previous post?

    Pls add jquery library to your html file. After adding 

    <script type="text/javascript" src="../../../../../../webresources/ClientGlobalContext.js.aspx"></script>add  this tag.

    Onload event of your html file you can set value to crm field.

    $( document ).ready(function() {
    window.parent.Xrm.Page.getAttribute('SrcCriteria').setValue('fgrhr');
    });

    This code works on live project. Pls try this and mark as answered if it is helpful for you.

    And below code is extremely unsupported!

    var textcontrol = document.getElementById("SrcCriteria");
    textcontrol.value = "Some text";


    Polat Aydın Crm Software Developer




    Tuesday, August 26, 2014 5:24 PM
  • Thankyou for the help, however...

    Altering the code to the supported method

                function btn_Press()
                {
                    // Get value of text box
                    //alert(document.getElementById('SrcCriteria').value);
    
                    // set value of textbox
                    //var textcontrol = document.getElementById("SrcCriteria");
                    //textcontrol.value = "Some Text";
                    window.parent.Xrm.Page.getAttribute('SrcCriteria').setValue('Some Text');
    
                    // retrieve emails for entity
                    retrieveEntityEmails()
                }

    The debugger shows an error on the line - "Unable to get property 'setValue' of undefined or null reference"

    Top of file looks like this:

    <HTML><HEAD><TITLE>Opportunity Header</TITLE>
    <SCRIPT type=text/javascript src="../Scripts/jquery1.4.1.min.js"></SCRIPT>
    
    <SCRIPT type=text/javascript src="../../../../../../webresources/ClientGlobalContext.js.aspx"></SCRIPT>

    regards,

    Matt


    Wednesday, August 27, 2014 8:58 AM
  • If I add the following file as a html webresource:

    <HTML><HEAD><TITLE>Opportunity Header</TITLE>
    <SCRIPT type=text/javascript src="../Scripts/jquery1.4.1.min.js"></SCRIPT>
    
    <SCRIPT type=text/javascript src="../../../../../../webresources/ClientGlobalContext.js.aspx"></SCRIPT>
    
    <SCRIPT>
        $(document).ready(function(){
            debugger;
            });
    </SCRIPT>
    
    <META>
    <META>
    <META>
    <META charset=utf-8></HEAD>
    <BODY contentEditable=true style="WORD-WRAP: break-word">
    </BODY></HTML>


    Click ok, then click text editor, then source, the file opens as

    <HTML><HEAD><TITLE>Opportunity Header</TITLE>
    <SCRIPT type=text/javascript src="../Scripts/jquery1.4.1.min.js"></SCRIPT>
    
    <SCRIPT type=text/javascript src="../../../../../../webresources/ClientGlobalContext.js.aspx"></SCRIPT>
    
    <SCRIPT>
        $(document).ready(function(){
            debugger;
            });
    </SCRIPT>
    
    <META>
    <META>
    <META>
    <META charset=utf-8></HEAD>
    <BODY contentEditable=true style="WORD-WRAP: break-word">
    <SCRIPT type=text/javascript src="/ATest/_common/global.ashx?ver=141881304"></SCRIPT>
    
    <SCRIPT type=text/javascript src="/ATest/_common/windowinformation/windowinformation.js.aspx?lcid=1033&amp;ver=141881304"></SCRIPT>
    
    <SCRIPT type=text/javascript src="/ATest/_common/entityproperties/entitypropertiesutil.js.aspx?tstamp=-614233227&amp;ver=141881304"></SCRIPT>
    </BODY></HTML>

    Note the script lines at the bottom of the file

    Matt

    Wednesday, August 27, 2014 9:14 AM
  • Hi,

    I try your example , and ı can get the textbox value from html webresource and set to the crm field.

    I add your html into Quote entity as subgrid.

    You can see the code screenshots below


    Polat Aydın Crm Software Developer

    Wednesday, August 27, 2014 11:48 AM
  • If I try the

    <HTML><HEAD><TITLE>Opportunity Header</TITLE>
    <SCRIPT type=text/javascript src="../Scripts/jquery1.4.1.min.js"></SCRIPT>
    
    <SCRIPT type=text/javascript src="../../../../../../webresources/ClientGlobalContext.js.aspx"></SCRIPT>
    
    <SCRIPT>
        $(document).ready(function(){
        $('#SrcCriteria').val("mynewvalue");
        var myinputval = $('#SrcCriteria').val();
        window.parent.Xrm.Page.getAttribute('name').setValue(myinputval);
            debugger;
            });
    </SCRIPT>
    
    <META>
    <META>
    <META>
    <META charset=utf-8>
    <META></HEAD>
    <BODY contentEditable=true style="WORD-WRAP: break-word"><INPUT id=SrcCriteria>
    </BODY></HTML>

    I get an error "The value of property '$' is null or undefined, not a function object".

    Thanks for all your effort with this, could it be the system is not set-up correct or ?

    Matt

    Wednesday, August 27, 2014 12:03 PM
  • Also I am CRM 2011 not 2013 like you should this make a difference?

    Matt

    Wednesday, August 27, 2014 12:18 PM
  • No , it is exactly work same in crm 2011

    And if $ is null or undefined your libraries could not load correctly. You put jquery library as webresource?

    If not pls make sure jquery library load correctly.You can add jquery as webresource and use like

     <script type="text/javascript" src="yourdevelopmentprefixofcrm_/Scripts/Jquery.js"></script>


    Polat Aydın Crm Software Developer


    Wednesday, August 27, 2014 1:07 PM
  • I have checked and it is in html web resource  as:

    <SCRIPT type=text/javascript src=".../Scripts/jquery1.4.1.min.js"></SCRIPT>

    I have also looked at the Web resources and it is there against our solution.

    I have now changed it to, as you suggested,

    <SCRIPT type=text/javascript src="ourdevelopmentprefix_/Scripts/jquery1.4.1.min.js"></SCRIPT>

    I still receive the same error.

    If I look at the default solution I can see that jquery.js was also added by the company that set the system up, if I add that to my webresource it fails with the same error.

    Am at a loss with this.

    Matt

    Wednesday, August 27, 2014 2:21 PM
  • Matt,

    ourdevelopmentprefix like new ,it is a  three character prefix. . It is your publisher name.

    Adding a webresource javascript to your custom html file is very simple.Pls look at my previous post in this topic.

    if $ is null or undefined in your html file , you can not add jquery library with success.

    Check out this url!

    http://msdn.microsoft.com/en-us/library/gg309536.aspx


    Polat Aydın Crm Software Developer





    Wednesday, August 27, 2014 2:39 PM
  • Polat,

    I have used our company name for the "Ourdevelopmentprefix" - sorry for any confusion.

    I understand what you are saying that the error says that it is not loaded but is there any other way I can check because as far as I can see from your examples everything is as it should be.

    regards,

    Matt

    Wednesday, August 27, 2014 2:48 PM
  • You can add jquery library from the url.

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>


    Polat Aydın Crm Software Developer

    • Marked as answer by Matt_Hirst_UK Wednesday, August 27, 2014 3:20 PM
    Wednesday, August 27, 2014 2:53 PM
  • That works perfectly, thanks for all your help!  Now this means the reference is wrong however I have checked it and can see it is in the default solution as 

    <SCRIPT type=text/javascript src="ourdevelopmentprefix_/Scripts/jquery1.4.1.min.js"></SCRIPT>

    it is published, otherwise it wouldn't appear in the default solution so I don't understand how I cannot reference it, only via the url link?

    Matt


    Wednesday, August 27, 2014 3:23 PM
  • Matt,

    you can see my examples , i give jquery reference like new_/jquery.js . I recommend you to check your webresource name , if it is true , it must be worked.Pls check again your jquery library name from customization-->webresource screen.


    Polat Aydın Crm Software Developer



    Wednesday, August 27, 2014 4:18 PM
  • I have removed the jquery1.4.1.min.js from the solution and re-added it Name: anc_/Scripts/jquery1.4.1.min.js and then updated the line to

    <SCRIPT type=text/javascript src="anc_/Scripts/jquery1.4.1.min.js"></SCRIPT>

    and it fails with "The Value of property '$' is null or undefined, not a function object".

    I will leave it with the http connection string for now.

    The problem I have is the install was undertaken by two seperate companies for us and we have no documentation with it at all.

    regards,

    Matt

    Thursday, August 28, 2014 8:34 AM
  • If I look at the webresource for JQuery it gives the full URL for the webresource and using the full URL it works so yes I think you are right it is not linked correctly however, shortening the URL to the just the server and location it fails...

    regards,

    Matt

    Thursday, August 28, 2014 8:47 AM