Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Add Record Creator to New Record

Questions related to customising nuBuilder Forte with JavaScript or PHP.
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

Re: Add Record Creator to New Record

Unread post 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.
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

Re: Add Record Creator to New Record

Unread post 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.
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Add Record Creator to New Record

Unread post 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');
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

Re: Add Record Creator to New Record

Unread post by pmjd »

Great, thanks you kev1n, have got it working now 8-)
Post Reply