Add Record Creator to New Record

Questions related to customising nuBuilder Forte with JavaScript or PHP.

Re: Add Record Creator to New Record

Unread postby kev1n » Fri Jul 02, 2021 12:30 am

kev1n
nuBuilder Team
 
Posts: 2050
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Add Record Creator to New Record

Unread postby pmjd » Fri Jul 02, 2021 7:13 pm

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.
pmjd
 
Posts: 96
Joined: Fri Mar 12, 2021 7:08 pm
nuBuilder Version: 4.5

Re: Add Record Creator to New Record

Unread postby pmjd » Mon Jul 05, 2021 11:01 pm

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.
pmjd
 
Posts: 96
Joined: Fri Mar 12, 2021 7:08 pm
nuBuilder Version: 4.5

Re: Add Record Creator to New Record

Unread postby kev1n » Mon Jul 05, 2021 11:38 pm

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');
kev1n
nuBuilder Team
 
Posts: 2050
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: Add Record Creator to New Record

Unread postby pmjd » Tue Jul 06, 2021 12:16 am

Great, thanks you kev1n, have got it working now 8-)
pmjd
 
Posts: 96
Joined: Fri Mar 12, 2021 7:08 pm
nuBuilder Version: 4.5

Previous

Return to Custom Code

Who is online

Users browsing this forum: pmjd and 6 guests