none
how get current site url in infopath

    Question

  • Hi all,

    I have a main site with a Project management form list, and I created subsites, on these subsites I have only webpart view forwarding main Project list form. My intention is, on the moment that my users access the subsite, and I will create a site to each Project and on the moment that will be access the webpart view to create a new Project task, the name of the Project must be completed by InfoPath rules having as reference the current url site, but I am not able to do this, because InfoPath Always give the url from the site where the list was created, in this case on Main site.

    is there on solution for this? get the current site url and use this information as a title in a form webpart view in a subsite?

    sorry for my english ...


    Certified (35) | ITIL | MCP | MCDST | MCSA1 | MCSE1 | MCT | MCTS Sharepoint | MCITP SQL | MCSA Windows 2012 | MTA Security | MCSE Windows 8 | MCSE Windows 2012 | Vencedor do Winthe7.com.br 2009, Quarto lugar Copa de Talentos Microsoft 2010

    Tuesday, August 12, 2014 2:25 PM

Answers

All replies

  • Hi,

    According to your post, my understanding is that you wanted to get current site url in InfoPath.

    By design in InfoPath, SharePointSiteUrl() return the address of the SharePoint site where the form is hosted.

    The Project management form is hosted in the main site, SharePointSiteUrl() will return the main site URL.

    As a workaround, you use JQuery code to change the value of the filed. Howerver, you need to check whether the form is in the main site or the subsite.

    You can follow the steps as below:

    1. Create a list, customize the form.
    2. Open the list, new item, find the URL of the new form.
    3. Open the new form page in the brower, edit page, insert a Content Editor Web Part.
    4. Insert the JQuery code into the web part.
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    
    <script type="text/javascript">
    
        $(document).ready(function () {
    
                    if(location.href.indexOf("?")!=-1){
    
                                    
    
                                    var url= parent.window.location.href;    
    
                                                    var test1= url.lastIndexOf("/");
    
                                                    var test2= url.indexOf("?");
    
                                                    var url1=url.substring(test1+1, test2);
    
                                                    if(url1!="newifs.aspx"){
    
                                                                    var url2=url.substring(0, test1);
    
                                                       $("input[id='ctl00_ctl41_g_d82ae428_002f_4511_bbc7_a82127cf0615_FormControl0_V1_I1_T2']").val(url2);                                                                
    
                        }
    
                    }
    
                    });     
    
    </script>

    You need to change “ctl00_ctl41_g_d82ae428_002f_4511_bbc7_a82127cf0615_FormControl0_V1_I1_T2'” to the id of your textbox.

         5. Open the subsite, insert the Page View WebPart to display the created list.

         6. Add item  in the Page View WebPart, it will display the subsite url.

    Thanks,

    Linda Li                

    Forum Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Linda Li
    TechNet Community Support


    Wednesday, August 13, 2014 3:38 AM
  • Many thanks Linda for your comment. 

    I ´m quite sure that I did something wrong, I followed your steps but I was not able to get the current url subsite on the moment that I´m creating a new item. 

    this is my main site http://sitename/sites/cdpmo. My intention is capture the sitename to use it on a field named ProjectName on the form.

    and after included the Jquery code, I inserted as page view webpart on the subsite http://sitename/sites/cdpmo/template, but conitinue showing the url from the main site.


    Certified (35) | ITIL | MCP | MCDST | MCSA1 | MCSE1 | MCT | MCTS Sharepoint | MCITP SQL | MCSA Windows 2012 | MTA Security | MCSE Windows 8 | MCSE Windows 2012 | Vencedor do Winthe7.com.br 2009, Quarto lugar Copa de Talentos Microsoft 2010

    Wednesday, August 13, 2014 11:23 AM
  • Hi,

    In my environment, if I add item in the main site, the URL is

    https://sitename/Lists/A%20Form/Item/newifs.aspx?List=db738cfd%2D3739%2D4367%2Dbf43%2Dde049aae9fcc&Source=https%3A%2F%2Fsitename%2FLists%2FA%2520Form%2FAllItems%2Easpx&RootFolder=&Web=afd6272f%2Dfd1d%2D4823%2Da7a8%2Daa042a070702

    Then I can extract “newifs.aspx” as url1. If your environment is not “newifs.aspx”, you need to change “if(url1!="newifs.aspx")”.

    If I add item in the sub site, the subsite url is

    https://sitename/Linda/Project%20Site/default.aspx?PageView=Shared&InitialTabId=Ribbon.WebPartPage&VisibilityContext=WSSWebPartPage

    The url1 will be "default.aspx".

    In addition, please make sure you change “ctl00_ctl41_g_d82ae428_002f_4511_bbc7_a82127cf0615_FormControl0_V1_I1_T2'” to the id of your textbox.

    Thanks,

    Linda Li                

    Forum Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Linda Li
    TechNet Community Support



    Thursday, August 14, 2014 1:43 AM
  • Hi Linda Li,

    tks for your tip, and could be used without problem.

    as workaround on my environmente I used another strategy.

    On the site collection, I created a new page, then I added 2 web parts to the page, first the InfoPath Form Web Part, and the Query String (URL) Filter web part. And on the query parameter I used the field related the name of project item.

    http://blogs.msdn.com/b/infopath/archive/2010/06/03/how-to-pass-querystring-data-into-an-infopath-form.aspx

    After that the challenge was how use this page on the subsites, then I decided to work with Content editor code getting the url from the page created on the root site.

    Then I used the instructions founded on this site to remove the frames related to root site.

    http://www.intrateam.com/gb/artikel/sharepoint-tip-framing-another-website

     

    <div style="width: 1000px; height: 1400px; >

    <iframe src="/sites/CDPMO/Project List/Reference.aspx?SiteURL=ReferenceProject" scrolling="no"

        style="margin- width: 1200px; height: 1500px; margin->

    </iframe>

    </div>


    All rules that I created has reference to the Project Name, to hide fields, permissions, workflows, etc, then is very important that this field is filled automatically in each subsite.

    tks


    Certified (35) | ITIL | MCP | MCDST | MCSA1 | MCSE1 | MCT | MCTS Sharepoint | MCITP SQL | MCSA Windows 2012 | MTA Security | MCSE Windows 8 | MCSE Windows 2012 | Vencedor do Winthe7.com.br 2009, Quarto lugar Copa de Talentos Microsoft 2010

    • Marked as answer by Adriano Neiva Thursday, August 14, 2014 2:30 PM
    Thursday, August 14, 2014 2:29 PM