how can I add new Item with 2 parentID

rss

Posted by wdksa1 - Mar 16 ’14 at 07:54

Hello ..

 

I have 3 list .. agremnt , LIC and Invice ..

 

I want to link Invoice with the agremnt and LIC list ..

 

I try to use this :

 

http://formsdesigner.blogspot.com/2013/08/how-to-create-forms-with-related-items.html

 

but I have 2 field that I need to link it one from LIC and the other from agremnt ..

 

I try to use it like this :

 


var licID = fd.getSourceID();if (licID) { fd.field('licID').control().value(licID); $('.licIDhid').hide();}

var agremntID = fd.getSourceID();if (agremntID) { fd.field('agremntID').control().value(agremntID); $('.agremntIDh').hide();}

but it faild !
It shows the same ID for both feild agremnt and lic ..

 

thank you .. smile

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 2 months 8 days
    #1 by Dmitry Kozlov Mar 17 ’14 at 06:06

    Hello,

    Thank you for your request. You cannot pass additional arguments from the parent form. But you can query field values from the parent form if you open the child form in a dialog. Put the following code into the child form via JS-editor of Forms Designer.

    if (window.top != window.self){
        alert(window.top.fd.field('Title').value());
    }
    
  • wdksa1
    Member
    Member for: 7 years 8 months 13 days
    #2 by wdksa1 Mar 17 ’14 at 06:32

    I got an alert which say "undefined"

    I was doing the Idea before by using JavaScript .. this is the code :

     

    <input id="btnGetLookUp" onclick="getLookUp()" type="button" value="add new invoce" />

     

    <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script>

    <script language="ecmascript" type="text/ecmascript">

     

    var listItem;

    var list;

    var clientContext;

     

    function getLookUp() {

     

    var SelectedID = getParameterByName("ID");

    this.clientContext = SP.ClientContext.get_current();

    if (this.clientContext != undefined && clientContext != null) {

    var webSite = clientContext.get_web();

     

     

    // ((1))  here change the list name

    this.list = webSite.get_lists().getByTitle("lic");

    this.listItem = list.getItemById(SelectedID);

    clientContext.load(this.listItem);

    this.clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));

    }

     

    }

     

    function OnLoadSuccess(sender, args) {

     

    // ((2))  here change the Item name you need to add it to the URL

    var lookup = this.listItem.get_item("agremntID");

    var SelectedID2 = getParameterByName("ID");

     

    // ((3))  here change the URL to the new form.

    var newItemLink1 = 'http://domain.org/property/Lists/lic_fine/NewForm.aspx?LicID=' + SelectedID2 + '&agremntID=' + lookup.get_lookupId();

    window.open(newItemLink1,"_self");

     

    }

     

    function OnLoadFailed(sender, args) {

     

    alert('Request failed. contact Admin ' + args.get_message() + '\n' + args.get_stackTrace());

     

    }

     

    function getParameterByName(name)

    {

    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

    var regexS = "[\\?&]" + name + "=([^&#]*)";

    var regex = new RegExp(regexS);

    var results = regex.exec(window.location.href);

    if(results == null)

    return "";

    else

    return decodeURIComponent(results[1].replace(/\+/g, " "));

    }

     

    </script>

    but when I use this code with forms designer it doesn't work how can I use your code and what can I do ? thank you .. smile
  • wdksa1
    Member
    Member for: 7 years 8 months 13 days
    #3 by wdksa1 Mar 17 ’14 at 07:44

    This is my issue : issue

     

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 2 months 8 days
    #4 by Dmitry Kozlov Mar 17 ’14 at 11:08

    [#3]: Do you open license and invoice forms in dialogs? If so, please, use the following code to get ID of agreement:

    alert(window.top.GetUrlKeyValue('ID'));
    
  • wdksa1
    Member
    Member for: 7 years 8 months 13 days
    #5 by wdksa1 Mar 18 ’14 at 02:35

    could you please explain with a little details because I don't understand where can I put this code and how can I get the two ID lic and agreement ?

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 2 months 8 days
    #6 by Dmitry Kozlov Mar 18 ’14 at 02:56

    [#5]: Use this code in the invoice form. So, to get the license ID, you will use:

    var licID = fd.getSourceID();
    

    And to get the agreement ID, please, use the following line:

    var agremntID = window.top.GetUrlKeyValue('ID')
    
  • wdksa1
    Member
    Member for: 7 years 8 months 13 days
    #7 by wdksa1 Mar 18 ’14 at 03:33

    Thank you verry much MR.Dmitry Kozlov .. but may I didn't get it ..  Should I open license from agremnt form ? becouse the user on my sharepoint open license from license list so is this the problem ? I try to put the last 2 codes on Js-editor on invoice form but it doesn't get any ID .. so should I make the user go to agremnt then to lic after that to invoce form ?

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 2 months 8 days
    #8 by Dmitry Kozlov Mar 19 ’14 at 02:28

    [#7]: Ok, if users create new invoices from a license form, you can use window.top.fd object to get field values of the parent form: window.top.fd.field('Agreement').value()

  • wdksa1
    Member
    Member for: 7 years 8 months 13 days
    #9 by wdksa1 Mar 19 ’14 at 04:36

    Dear Demitry,

    I think we still have misunderstanding. I tried the last function too, but still I face the same problem.

    Let's me explain that to you again. I have agreement list which is parent list and I have license list which child of agreement list. then I have an invoice list which is child for both agreement and license lists. Both agreement list and license list are an lookup columns in invoice list. I want to shows the agreement ID field and license ID field (which they are lookup columns) in the Invoice list. so, Each license just have only one agreement and I want to get some fields from agreement list and license lists.

    Wish this details can help you more for my issue.

  • eedoh
    Member
    Member for: 7 years 9 months 27 days
    #10 by eedoh Mar 24 ’14 at 06:40

    [#9]: Why don't you use cookies? Just make them available through the whole site (set path attribute to "/").

    ON SOURCE FORMS!

    var licID = fd.getSourceID();if (licID) { fd.field('licID').control().value(licID); $('.licIDhid').hide();}
    document.cookie = "LICID="+licID +"; path=/";

    var agremntID = fd.getSourceID();if (agremntID) { fd.field('agremntID').control().value(agremntID);
    document.cookie = "AID="+agremntID+"; path=/";

     

    ON TARGET FORM

    var licID = document.cookie.replace(/(?:(?:^|.*;\s*)LICID\s*\=\s*([^;]*).*$)|^.*$/, "$1");
    var agremntID = document.cookie.replace(/(?:(?:^|.*;\s*)AID\s*\=\s*([^;]*).*$)|^.*$/, "$1");

Displaying 1 to 10 of 22 messages
Previous123