Silvestre Kassoka

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 34 total)
  • Author
    Posts
  • in reply to: VLOOKUP #29768
    Silvestre Kassoka
    Participant

    Hi Alex,

    Thanks a billion!!!. It working like a Charm.!!!

    in reply to: VLOOKUP #29762
    Silvestre Kassoka
    Participant

    Hi Alex,

    Thanks for your help as usual. However calling the function i get an error

    Reference error:CountDaysBetween not defined.

    in 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

    in reply to: VLOOKUP #29621
    Silvestre Kassoka
    Participant

    Thanks ,

    Here goes, basically I have two custom lists which are Employees and Leave Request form.
    The employees list a the leave balances of the employees and the leave request is used for submitting the form. When submitting the form the number of days taken is calculated(sharepoint calculation) by end date-start date..The calculated column has a field internal name dias.

    If the the days taken (dias) in greater than the balance then from should hide save and give notice you only have x days available.
    In a nutshell this what we are trying to achieve it .I think the only problem is the calculated column.

    v 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]);
    }

    })();

    jQuery(“#dffs_dias input”).on(“change”, function () {
    dias = Number(this.value);
    console.log(dias);
    console.log(balance);
    if (dias > 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 (dias > balance) {
    spjs.dffs.alert({
    “title”: “Unable to save request”,
    “msg”: “You only have ” + balance + ” hours available.”
    });
    return false;
    }
    return true;
    }

    in reply to: VLOOKUP #29613
    Silvestre Kassoka
    Participant

    Sorry forgot to add that its a normal Sharepoint calculated list.

    in reply to: VLOOKUP #29611
    Silvestre Kassoka
    Participant

    Alex,

    I am afraid not with that as well.I continue to get the same errors i posted earlier.

    Regards

    in reply to: VLOOKUP #29588
    Silvestre Kassoka
    Participant

    No Alex, I am triggering on the change of calculated field. The calculated field is
    based on end date-start date which is the dias column.

    Regards

    in reply to: VLOOKUP #29581
    Silvestre Kassoka
    Participant

    Hi Alex,

    You are right! Apparently after the jQuery nothing is logged , however they are some errors that come up . I have attached for your reference

    jQuery(“#dffs_dias”).on(“change”, function () {
    dias = Number(this.value);
    console.log(dias);
    console.log(balance);
    if (dias > balance) {
    spjs.dffs.toggleSaveBtnByRule(false);
    spjs.dffs.alert({
    “title”: “To many hours requested”,
    “msg”: “You only have ” + balance + ” hours available.”
    });

    in reply to: VLOOKUP #29567
    Silvestre Kassoka
    Participant

    Hi Alex,

    Thank you so much the query came out right.How even the {{var:balance}} is now displaying right.

    However, this portion of
    jQuery(“#dffs_dias input”).on(“change”, function () {
    dias = Number(this.value);
    if (dias > balance) {
    Even logging nothing it nothing is being returned. my field internal name is “dias”.

    in reply to: VLOOKUP #29554
    Silvestre Kassoka
    Participant

    Hi Alex,

    From object i can tell the query portion of the script is fine. It’s the other parts of the code that seem not to be working. find attached.

    Attachments:
    in reply to: VLOOKUP #29546
    Silvestre Kassoka
    Participant

    Hi Alex,

    Thanks for the heads up.well. i spend the whole day cracking on this but cannot seem to get the hang of it.

    From the logs, i can tell that the query is working fine which is is the first part of the code.

    (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”]

    However , the portion below is getting an undefined.
    if (res.count > 0) {
    var item = res.items[0];
    balance = Number(item.Ferias_x0020_para_x0020_Gozar);
    }
    console.log(item);

    The other log errors i cannot interpret i just attached them.

    in reply to: VLOOKUP #29534
    Silvestre Kassoka
    Participant

    Hi Alex,

    Thanks a lot, sure his request is pretty much similar to mine and it sure was good start.The only difference is that is my case is the number of days taken is a calculated field based on start & end date.

    However, in my case the following is happening,
    a). The rule that calls the JS is kicking well but nothing is happening.I console.logged the res variable(log attached) it appears its not querying that Employees list.

    I am also thinking its because my number of days requested <strong/> value is a calculated column ,probably when the JS kicks that field will still not a value.I am not sure.

    On a side note, I tried to use the {{var:balance}} to display balance of hours but to know success.print attached.

    Thank you in advance.

    in reply to: Caculated files #29096
    Silvestre Kassoka
    Participant

    Hi Alex,

    Sorry i missed that bit.

    As always thanks a lot , its working exactly as i intended!!!

    Regards

    in reply to: Caculated files #29084
    Silvestre Kassoka
    Participant

    Hi Alex,

    Thanks the code actually work to insert the total value to the single line of text for the subsequent lookup the forms.However the value is no longer being displayed on the form. Actually the system throw an error , see annex.

    Attachments:
    in reply to: Caculated files #29075
    Silvestre Kassoka
    Participant

    Hi Alex,

    I think that’s the problem the values on gets displayed on the form however when i save the form and go to the list item the i see no value corresponding to that column.I have attached the file that shows the JS code doing the calculations.

    Attachments:
Viewing 15 posts - 1 through 15 (of 34 total)