Skip to main content

Search

Custom .js in expressions

Comments

14 comments

  • Andreas_Meier

    Dear Senad Omicevic

     

    This is not possible to do. If you want that this is placed on our Backlog in the future please create an Idea:

    Ideas SharePoint Add-Ins 

     

    The only thing that would work is to add script editor web part to the form and reference that js script.
    suppose that file contains some thing like this:
    function SomeFunction(a){
       alert( a );
    }

     

    then from expressions you can call the function from script file:

    window.SomeFunction([[Title]])

    But you cannot use our placeholders in the js file itself.

     

    Kind Regards

    Andreas Meier

    0
  • Senad

    Hello Andreas,

     

    thank you for your answer. 

     

    Is it possible to use it somehow in variables?

     

    Create a global variable, assign the value of a placeholder and then call the js which uses this variable?

    0
  • Andreas_Meier

    Dear Senad Omicevic

     

    Yes this is possible.

     

    Kind Regards

    Andreas Meier

    0
  • Senad

    Hello,

     

    can you please tell me what would be the approach to get this work?

     

    Lets say I have this code in my custom.js

     

    var wantedDay;

    wantedDay = myDate.getDay();

    return wantedDay

     

    And before the .js I would use this:

     

    var myDate = [[MyDateField]];

     

    How do I need to write the whole code to call the custom.js and use the second part?

     

    Thank you in adnvace

    0
  • AndriiK

    Hi Senad,

     

    In this case you should write a function for wantedDay in custom.js

    e.g:

    function GetWantedDate(myDate)
    {
        var wantedDay;
        wantedDay = myDate.getDay();
        return wantedDay;
    }

     

    and call this function from expression:

    var myDate = [[MyDateField]];
    var wantedDate = window.GetWantedDate(myDate);

     

    Sincerely,

    Andrii Katsiubka

    0
  • Senad

    Hi Andrii,

     

    thank you for your answer.

     

    My custom.js would be on another site, how can I load it inside a expression?

     

    Thank you.

    0
  • AndriiK

    It is not necessary to load script inside an expression. It will be enough just to add script reference to the page.

    Just add Script Editor Webpart to your page and insert next code:

    <script type="text/javascript" src="linkToJsFile"></script>

    where linkToJsFile should be replaced by the path to custom.js file.

    0
  • Senad

    Thank you Andrii,

     

    this is working.

     

    I have faced a problem when I use jQuery actions in my custom.js, I get this msg: jQuery is not a function

     

    It seems its not using the loaded jQuery functions inside my form.

     

    How can I fix this? 

     

    Thank you.

    0
  • AndriiK

    There are few option how to use jQuery:

    1. Reference jQuery in Script Editor webpart before custom.js script
    2. To use ArdeviaJQuery object instead of jQuery, but this object can be unavailable while RichForms scripts will not be loaded
    0
  • Senad

    It is okay to use the ArdeviaJQuery because I am trying to use this line:

     

    jQuery(e).val();

     

    aren't all RF scripts loaded automatically when the form is loaded? But seems they are not used in the external scripts. 


    All this is in a NewForm. 

    0
  • AndriiK

    In Expressions jQuery and ArdeviaJQuery is the same, but from external scripts only ArdeviaJQuery is available.

    RF scripts are loaded automatically, so if you will use ArdeviaJQuery from ScriptEditor web part it should work.

    0
  • Senad

    Hi Andrii,

     

    I am not sure if I understood correctly. With ArdeviaJQuery you mean the three jquery js files in FormsStoreLibrary? I have made a ScriptEditor and loaded all jQuery scripts from the script folder in FormsStoreLibrary with my custom script and it looks like this:

     

    <script type="text/javascript" src="mySite/FormsStoreLibrary/Scripts/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="mySite/FormsStoreLibrary/Scripts/jquery_ui.custom.min.js"></script>
    <script type="text/javascript" src="mySite/FormsStoreLibrary/Scripts/jquery.form.min.js"></script>
    <script type="text/javascript" src="mySecondSite/SiteAssets/custom.js"></script>

     

    I get the same error when I do it like this. 

    0
  • AndriiK

    Hi Senad,

     

    If you want to use ArdeviaJQuery you don't need to reference jquery in Script Editor Webpart, because it is already referenced in RichForms.

    0
  • Senad

    Thank you, 

     

    after I changed the jQuery lines it's working now.

    0

Please sign in to leave a comment.