Discussions

Expand all | Collapse all

Using iol to Select Tab of Child After Adding Child Record

  • 1.  Using iol to Select Tab of Child After Adding Child Record

    Posted 26 days ago
    Edited by Brandon Clark 26 days ago
    I am trying to move my Add Child buttons up out of the tabs and on to the main form.  To keep it from appearing awkward, I also would like to have the associated tab selected after adding the child record.  Due to lack of talent, I've taken a two step approach.  The first is the Add Child button now also sets fid_104 to the tab number of the associated child table prior to adding the record. 

    The second part is to use iol to set the focus to the desired tab on reload.  I have just the basic iol setup and a codepage with the following which successfully changes the focus to tab 11 on reload:

    $("#tab_t11_link a").click();

    What I am would like to do is have it read in the value of  fid_104 as a variable, if it is not "0", then use the variable to set the appropriate tab focus and set the fid_104 to "0".  

    Any help is appreciated.


    ------------------------------
    Brandon Clark
    ------------------------------


  • 2.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 25 days ago
    Post your formula for the Add Child buttons, you should be using the native & "&z=" & Rurl() and it should return to the correct tab after adding a child record. 

    ------------------------------
    Everett Patterson
    ------------------------------



  • 3.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 25 days ago
    Thanks for the reply Everett.  Code from button below. 

    The issue is that the button to add the child record is not on the child record tab for us.  It basically saves the user from having to click the tab header and then click add child.  This way they just click add child and then when completed it returns them with the correct tab in focus so they can see it come through and review/edit if required.  

    URLRoot() & "db/" & [_DBID_CONTACTS] & "?a=API_EditRecord&rid=" & URLEncode ([Record ID#])
    & "&_fid_104=11"
    & "&rdr="
    & URLEncode(URLRoot() & "db/" & [_DBID_OPPORTUNITIES] & "?a=API_GenAddRecordForm&_fid_17=" & URLEncode ([Related Company])& " &_fid_43=" & URLEncode ([Record ID#])& "&z=" & Rurl())

    ------------------------------
    Brandon Clark
    ------------------------------



  • 4.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 25 days ago
    Edited by Everett Patterson 25 days ago
    Sorry I must have misunderstood, you are wanting a function within the code page that looks at the value of _fid_104 and determines which tab to focus?

    (function () {
    //Get the expected tab value
    var QBUmytab = Number($("#tdf_1").text());
    //Go to tab based on value
    switch(QBUmytab) {
        case 3:
    		$("#tab_t3_link a").click();
    		break;
        case 4:
    		$("#tab_t4_link a").click();
    		break;
    };})();


    ------------------------------
    Everett Patterson
    ------------------------------



  • 5.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 21 days ago
    Hi Everett,

    I pasted the code in but nothing is happening.  Do you by chance have any debugging code I can insert to see if the variable is passing in and if the cases are selecting properly?  

    Thanks!
    Brandon

    ------------------------------
    Brandon Clark
    ------------------------------



  • 6.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 21 days ago
    Given the code above adding in the debugging is the easier part. You should get used to adding it in yourself because it helps you learn as you go.

    What I would do is start simple, a console.log(QBUmytab); after the variable is set in the code. If you see that it is returning something then go from there. Make sure it is returning what is expected which is some type of number, and if it is returning anything but the numbers listed(3 or 4) then it doesn't have anything in the code to call. If it is returning a 3 or 4 then chances are the code for those may not be exactly right.


  • 7.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 21 days ago
    Thanks Austin.  It appears the QBUmytab variable is not getting defined.  Did #tdf_1 need to be edited for my implementation or does that convert to fid_104?  I've tried simply changing to tdf_104 with no luck.
     
    (function () {
    //Get the expected tab value
    var QBUmytab = Number($("#tdf_1").text());
    console.log(QBUmytab);
    //Go to tab based on value
    switch(QBUmytab) {
    case 3:
    $("#tab_t3_link a").click();
    break;
    case 4:
    $("#tab_t4_link a").click();
    break;
    };})();

    And I agree on getting used to adding the troubleshooting code.  I probably have 30 hours into just trying to accomplish this one task.  But if I have this snip with the code to debug each step along the way then I can start using this as my reference example to build out from and start getting some context to better understand the javascript documentation.  

    Thx again,
    Brandon

    ------------------------------
    Brandon Clark
    ------------------------------



  • 8.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 21 days ago
    tdf# = div ID you want to target

    Use F12 dev tools, select an element and target your fid 104


    ------------------------------
    Everett Patterson
    ------------------------------



  • 9.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 21 days ago
    Ok, that was really good info.  So here's my first shot at dividing it up.  Both of the alerts with the values are displaying NaN.  
    It is not making into the Case 11 as expected.  

    (function () {
    //Get the expected tab value
    alert("lets go fishing");
    alert( Number($("#tdf_1").text());
    var QBUmytab = Number($("#tdf_1").text());alert(QBUmytab);
    //Go to tab based on value
    switch(QBUmytab) {   
       case 11: alert("No way, it's too nice out.");
          $("#tab_t11_link a").click();
         alert("But there's free bait!");
         break;   
       case 13:
          $("#tab_t13_link a").click();
          break;
    };})();

    ------------------------------
    Brandon Clark
    ------------------------------



  • 10.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 21 days ago
    So is tdf_1 your field that you found through the method Everett described? The error your are getting is telling you the field you are trying to convert into a number is not a number(NaN).

    I wouldn't normally use so many alerts but if you want to know what the field is just go to your form and type this into console.

    alert($("#tdf_1").text())

    And tell us what that says. I still feel like you just need to adjust the #tdf_1 part to be the correct number for your field you are wanting to check.


  • 11.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 20 days ago
    You nailed it.  I let the original parameter back in on a copy/paste.   The tab selection is working now.  And I now understand how to check the parts along the way.  You guys are awesome.  

    (Side note: For anyone else that is struggling with Javascript, I found this little tutorial to be a pretty efficient way to learn the basics - https://www.learn-js.org/ )

    Now for the last piece, I need to take a stab at setting the Tab # field ​back to 0 after the focus.    Will post what I figure out.  Here's the code page as it stands: 

    (function () {

    //Get the expected tab value

    var QBUmytab = Number($("#tdf_2").text());

     

    //Go to tab based on value

    switch(QBUmytab) {

         case 2:

                                $("#tab_t2_link a").click();

                                break;

        case 3:

                                $("#tab_t3_link a").click();

                                break;

        case 11:

                                $("#tab_t11_link a").click();

                                break;

        case 20:

                                $("#tab_t20_link a").click();

                                break;

       case 30:

                                $("#tab_t30_link a").click();

                                break;

    };})();


    ------------------------------
    Brandon Clark
    ------------------------------



  • 12.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 20 days ago
    Thanks for the JS link.   It is becoming more and more important to dig into the browser.   I will give it a long look over.

    ------------------------------
    Don Larson
    Paasporter
    Westlake OH
    ------------------------------



  • 13.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 20 days ago
    Edited by Everett Patterson 20 days ago
    You will need to add the API_EditRecord call to each case and it will set that field back to 0 after it does the focus. 

    Replace dbid with your dbid
    (function () {
    //Get the expected tab value
    var QBUmytab = Number($("#tdf_2").text());
    //Go to tab based on value
    switch(QBUmytab) {
        case 3:
    		$("#tab_t3_link a").click();
    		var dbidParents = "VALUE";
    		var rid = kRid;
    		$.post(dbidParents, {
    			act: "API_EditRecord",
    			rid: rid,
    			_fid_104: 0,
    		}).then(function(xml) {
    		});
    		break;
        case 4:
    		$("#tab_t4_link a").click();
    		break;
    };})();​



    ------------------------------
    Everett Patterson
    ------------------------------



  • 14.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 20 days ago
    It works brilliantly.  Everett you are genius.  Thank you.

    ------------------------------
    Brandon Clark
    ------------------------------



  • 15.  RE: Using iol to Select Tab of Child After Adding Child Record

    Posted 19 days ago
    Starting to see the first minor flaw in the plan.  The fid_104 is required to be visible on the form for this work.  ​I can live with that for now but any thoughts on a better way to pass the information without using it on the form?

    ------------------------------
    Brandon Clark
    ------------------------------