Skip to main content

Search

Extracting values from other lists

Comments

6 comments

  • Matthias_Walter

    Hi Sandra Huntley,

    the problem in this case will be, that the items from the NPFRDetails list are not yet saved especially on the newform, they are only in the grid before you save the form.

    To get the smallest and the largest number from a sublist, you can use an expression:

     

    Where do you try to execute this query? I think the best would be to use it in a calculated expression on the giving/receiving executive fields in the primary list.

     

    BR Matthias

    0
  • sangel40

    Hi Matthias,

     

    Sorry, I don’t think that I explained the issue very well.

     

    The steps that I am try to work through are as follows:

     

    I need to find the Management Unit for the NPFRDetail line that has the lowest value. With this Management Unit I need to query the REF-MANAGEMENT UNIT list to find the Executive Group code.

     

    I then need to find the Management Unit for the NPFRDetail line that has the highest value. With this Management Unit I need to query the REF-MANAGEMENT UNIT list to find the Executive Group code.

     

    Normally I would have had the Executive Group included as part of the Management Unit Lookup Column, but I need to add a record to balance so don’t have this information available.

    0
  • AndriiK

    Hi Sandra Huntley,

     

    I think it is possible to do with nested expressions.
    I will try to recreate your case and write a solution for it.

    0
  • AndriiK

    Unfortunalty nested expression for @Web.GetFirstValueForQuery will be in next release, so at the moment the solution will be without using that placeholder.

     

    Suppose on the form we have sublist NPFRDetail.

    NPFRDetail has fields:

    •    Amount (Number field)
    •    ManagementUnitRef (Lookup to ManagementUnit list)

    ManagementUnit has fields:

    • Title
    • ExecutiveGroupCode

     

    So we need to find ExecutiveGroupCode for list item from NPFRDetail sublist with min Amount.

    The next expression can do it:

    var webpartId = "NPFRDetail webpart id";
    var webpartSelector = "[ard-webpart-id=" + webpartId + "]";
    var gridController = jQuery(webpartSelector).data("Controller");
    var grid = gridController.InstanseData;
    var recordsIds = grid.GetAllRecordIds();
       
    var min = [[@SubLists.NPFRDetail.Amount.Min]];
    var lookupId = 0;
       
    for (var i = 0; i < recordsIds.length; i++){
       var id =  recordsIds[i];
       var unit = grid.GetRowValue(id, "ManagementUnitRef");
       var amount = grid.GetRowValue(id, "Amount");
       if (parseFloat(amount) == min){
         if(unit instanceof Array && unit[0]){
          lookupId = unit[0].lookupId;
         } else {
          lookupId = unit ? unit.split(";#")[0] : unit;
         }
          break;
       }
    }

    var ctx = new SP.ClientContext();
    var list = ctx.get_web().get_lists().getByTitle("ManagementUnit");
    var item = list.getItemById(lookupId);
    ctx.load(item);
    ctx.executeQueryAsync(function(){
      var group = item.get_fieldValues()['ExecutiveGroupCode'];
      alert(group);
    }, function(e,s){
    });

    On the place "NPFRDetail webpart id" should be the webpart id of NPFRDetail sublist
    To find executive group code you can use the same expression with one small change:

    •  replace Min by Max in [[@SubLists.NPFRDetail.Amount.Min]].
    0
  • sangel40

    Hi Andrii,

     

    This is what I used in the Execute Script and received no results. The line

    that starts with var ctx shows as an error with SP as not being defined.

     

      var webpartId = "3ef1d749-d70e-4bf0-b5d9-6a5d870917a7";
    var webpartSelector = "[ard-webpart-id=" + webpartId + "]";
    var gridController = jQuery(webpartSelector).data("Controller");
    var grid = gridController.InstanseData;
    var recordsIds = grid.GetAllRecordIds();
     
    var min = [[@SubLists.NPFRDetails.Amount.Min]];
    var lookupId = 0;
    for (var i = 0; i < recordsIds.length; i++){
      var id =  recordsIds[i]; alert("id = " + id);alert("sam");
       var unit = grid.GetRowValue(id, "ManagementUnit");
       var amount = grid.GetRowValue(id, "Amount");
       if (parseFloat(amount) == min){
         if(unit instanceof Array && unit[0]){
          lookupId = unit[0].lookupId;
         } else {
          lookupId = unit ? unit.split(";#")[0] : unit;
         }
          break;
       }

    var ctx = new SP.ClientContext();
    var list = ctx.get_web().get_lists().getByTitle("ManagementUnit");
    var item = list.getItemById(lookupId);
    ctx.load(item);
    ctx.executeQueryAsync(function(){
      var group = item.get_fieldValues()['ExecutiveGroup'];
      alert(group);
    }, function(e,s){
    }); 
    Regards
    Sandy
    0
  • AndriiK

    Try to replace var ctx = new SP.ClientContext(); with var ctx = new window.SP.ClientContext();

    0

Please sign in to leave a comment.