Reply To: VLOOKUP

Home Forums General discussion VLOOKUP Reply To: VLOOKUP

#29735
Silvestre Kassoka
Participant

    Hi Alex,

    Thanks a lot for the code but i continue to have some challenges.I will post the code first and explain.

    // To change date format since my forms are in Portuguese.
    spjs.dffs.data.lcidToDateFormat[“2070”] = “d/m/y”;
    function countDaysbetween(_x0066_ku0,_x0076_yt6){
    var r = {“businessDays”: 0, “weekendDays”: 0};
    var f = spjs.utility.getDateFieldAsDateObject(“_x0076_yt6”);
    var t = spjs.utility.getDateFieldAsDateObject(“_x0066_ku0”);
    console.log(t)
    console.log(f)
    if(f === “” || t === “”){
    // from or to date is empty
    return r;
    }
    // Set time to 12:00 to ease calcuation
    f.setHours(12,0,0);
    t.setHours(12,0,0);
    while(f <= t){
    var d = f.getDay();
    if(d > 0 && d < 6){ // 1 = Monday and 5 = Friday
    r.businessDays += 1;
    }else{
    r.weekendDays += 1;
    }
    f.setDate(f.getDate() + 1);
    console.log(r)
    }
    return r;
    }

    // Call it like this with from and to date fields as arguments
    var diff = countDaysbetween(“_x0066_ku0″,”_x0076_yt6”);
    var businessDays = diff.businessDays;
    var weekendDays = diff.weekendDays;
    console.log(diff)
    var balance = 0;
    var dias = 0;
    (function () {
    var res = spjs.utility.queryItems({
    “listName”: “Total de Ferias”,
    “query”: “<Where><Eq><FieldRef Name=’Person’ LookupId=’TRUE’ /><Value Type=’Integer’>” + _spPageContextInfo.userId + “</Value></Eq></Where>”,
    “viewFields”: [“ID”, “Ferias_x0020_para_x0020_Gozar”]

    });

    if(res.count > 0); {
    var item = res.items[0];
    balance = Number(item.Ferias_x0020_para_x0020_Gozar.split(“;#”)[1]);
    }

    })();

    function calculation () {
    console.log(businessDays);
    console.log(balance);
    if (diff > balance) {
    spjs.dffs.toggleSaveBtnByRule(false);
    spjs.dffs.alert({
    “title”: “To many hours requested”,
    “msg”: “You only have ” + balance + ” hours available.”
    });

    }else {
    spjs.dffs.toggleSaveBtnByRule(true);
    }
    }

    function dffs_PreSaveAction() {
    if (diff > balance) {
    spjs.dffs.alert({
    “title”: “Unable to save request”,
    “msg”: “You only have ” + balance + ” hours available.”
    });
    return false;
    }
    return true;
    }

    Challenges

    a) Console.log (t)
    b) console.log (f) cannot return value
    *print provided.
    c) When i call the function name
    ( countDaysbetween(_x0066_ku0,_x0076_yt6) in Rules i get error print provided.

    d) I am also struggling with using the r returned value in the calculation functions to achieve the intended.

    Thank you