Page 2 of 2

Re: Add Record Creator to New Record

Posted: Thu Jul 01, 2021 5:00 pm
by kev1n

Re: Add Record Creator to New Record

Posted: Fri Jul 02, 2021 11:43 am
by pmjd
Thanks Kev1n, hope you or another of the team can add this to the code library as it is a very useful and easy to solution.

Re: Add Record Creator to New Record

Posted: Mon Jul 05, 2021 3:31 pm
by pmjd
Hi kev1n,

I looked at the link and not sure where some of the code goes.

I added the following to the header

Code: Select all

function formatUnixDateTime(t, locales, dOptions, tOptions) {

    if (typeof dOptions === 'undefined') {
        var dOptions = {};
    }
    if (typeof tOptions === 'undefined') {
        var tOptions = {};
    }
    var d = new Date(t * 1000);
    return d.toLocaleDateString(locales, dOptions) + ' ' + d.toLocaleTimeString(locales, tOptions);
}

function getNuLogData(obj, type, what) {

    var undef = (typeof obj === 'undefined');
    var info = '<b>' + nuTranslate(type + ' ' + what) + ':</b> ';

    if (what == 'User') {
        return undef ? '' : info + obj.user + "<br>";
    } else
    if (what == 'Time') {
        return undef ? '' : info + formatUnixDateTime(obj.time, "en-US") + "<br>";
    }
}
But where does the next block go?

Code: Select all

function showNuLogInfo(id) {

    var nuLog = $('#' + id).val();
    var obj = JSON.parse(nuLog);

    var msg = getNuLogData(obj.added, 'Added', 'User') + getNuLogData(obj.added, 'Added', 'Time');
    msg += getNuLogData(obj.viewed, 'Viewed', 'User') + getNuLogData(obj.viewed, 'Viewed', 'Time');
    msg += getNuLogData(obj.edited, 'Edited', 'User') + getNuLogData(obj.edited, 'Edited', 'Time');

    nuMessage([msg]);
    $('#nuMessageDiv').css('text-align', 'left');
}
I tried the form's custom code and listed it as an onclick event but it doesn't seem to work.

Re: Add Record Creator to New Record

Posted: Mon Jul 05, 2021 4:08 pm
by kev1n
showNuLogInfo() can also be added to the Header.

Then call the function like this (replace example_nulog with you nulog object Id that has to be on the form)

Code: Select all

 showNuLogInfo('example_nulog');

Re: Add Record Creator to New Record

Posted: Mon Jul 05, 2021 4:46 pm
by pmjd
Great, thanks you kev1n, have got it working now 8-)