Page 1 of 1

Trying to create a form for extended search.

Posted: Wed Apr 26, 2023 9:37 am
by tsignadze
Hi, I have a browse form with primary key set as ID.
I have added button on every field with this code in forms custom code (below). I want this button to open a new launch form where there will be all the fields displayed I need from a SQL query with ID passed as WHERE clause.

as I understand, I need to create global hashcookie somehow.
I have set this code to open form ID 6448cef8823183b but it says access is denied, even tho I have turned on every access group there is for this detailed_search form.

Every bit of help will be appreciated as this is the last step to complete this project.

Code: Select all

// No action when clicking a cell
function nuSelectBrowse(e) {
    return false;
}
function createButton(target, pk, label, title, openAction) {
    let btn = $('<button type="submit" style="height:21px; border: none; vertical-align: top; background-color: #378bd5; transform: translateY(-10%); color:white">'+ label +'</button>');
    $(target).html(btn).attr('title', nuTranslate(title));
    btn.on('click', function() {
        openAction(pk);
    });
}
function addButons(column, label, title, openAction) {
    $("[data-nu-column='" + column + "']").each(function(index) {
        var pk = $(this).attr('data-nu-primary-key');
        if (typeof pk !== "undefined") {
            createButton(this, pk, label, title, openAction);
        }
    })
}


function openBrowseForm(pk) {
    nuForm('6448cef8823183b', '', '', '', '2');   // Filter the Browse form with the pk
}

// Add an edit and browse button
// Icon list: https://fontawesome.com/v5/search?m=free
addButons(0, '<i class="fas fa-search-plus"></i>', 'სრული დეტალების გახსნა', openBrowseForm);

Re: Trying to create a form for extended search.

Posted: Wed Apr 26, 2023 10:43 am
by kev1n
I understand that you mentioned setting a global hash cookie, but in you code, I couldn't find where or how the HK is used. Can you please clarify the implementation of the global hash cookie in your code?

Re: Trying to create a form for extended search.

Posted: Wed Apr 26, 2023 11:17 am
by tsignadze
Sorry, I have not described my goal clearly.

I have followed this post here : Add 2 columns to the browse form
This is what my browse form looks like, I want to achieve following: when I press extended search button, I want to open a new form where I will be able to display fields which I will grab from a query using HK coming from uppermentioned browse form, which will be ID or SerialNumber, I think ID because it is already setup as a primary key for browse form.

This is my understanding of how I should grab ID for each field. So I was thinking to make a function to set global HK when I press a button and use that in next extended search form. Is it correct? if so how do I manage that? I hope I clarified my goal better now.
Screenshot 2023-04-26 131444.png

Re: Trying to create a form for extended search.

Posted: Wed Apr 26, 2023 11:32 am
by kev1n
I still do not understand where/how this HK is used as there's no reference to it in your code.

Re: Trying to create a form for extended search.

Posted: Wed Apr 26, 2023 11:34 am
by tsignadze
I just copy pasted that code to get the button on browse screen Kev1n. I did not do anything else to the code.

Re: Trying to create a form for extended search.

Posted: Wed Apr 26, 2023 11:47 am
by kev1n
Are you also getting the error if you just run:

Code: Select all

nuForm('6448cef8823183b', '', '', '', '2');

Re: Trying to create a form for extended search.

Posted: Wed Apr 26, 2023 12:15 pm
by tsignadze
Yes, I don't understand why..

Re: Trying to create a form for extended search.

Posted: Wed Apr 26, 2023 12:22 pm
by tsignadze
Created a new form and it opens now.
I want to know how do I pass ID from browse forms row to a new form to get query results? If I search for something and I get a row, I want to press this extended search button which will pass ID from that row to a new form.

Re: Trying to create a form for extended search.

Posted: Wed Apr 26, 2023 1:09 pm
by kev1n
Important to know when setting a global Hash Cookie:
This function is asynchronous which means that it returns immediately without waiting for the server to complete the operation.
Instead, it triggers a callback function, nuOnPropertySet(), once the operation is complete, so that you can execute some code after the property has been successfully set.

Code: Select all

function nuOnPropertySet(i, nj) {
	if (i == 'your_hk') {
		nuForm('YOUR_FORM_ID_HERE', '', '', '', '0');
	}
}

Set global Hash Cookie:

Code: Select all

nuSetProperty('your_hk','some value', true);

Re: Trying to create a form for extended search.

Posted: Wed Apr 26, 2023 5:43 pm
by tsignadze
I have a difficulty understanding, as I understand, I have to use nuSetProperty when I click a button, what do I put in this functions parameters? Coming from that table which I have (browse form) how do I grub sql field called SerialNumber? and where do I run nuOnPropertySet?

Can you give me example code including mine? sorry for asking too much.

EDIT
Managed to get it working, finally understood things. Thanks Kev1n!!!
Here is my junk code if anyone will need it in the future:

Code: Select all

// No action when clicking a cell
function nuSelectBrowse(e) {
    return false;
}

function createButton(target, pk, label, title, openAction) {
    let btn = $('<button type="submit" style="height:21px; border: none; vertical-align: top; background-color: #378bd5; transform: translateY(-10%); color:white">'+ label +'</button>');
    $(target).html(btn).attr('title', nuTranslate(title));
    btn.on('click', function() {
        openAction(pk);
    });
}

function addButtons(column, label, title, openAction) {
    $("[data-nu-column='" + column + "']").each(function(index) {
        var pk = $(this).attr('data-nu-primary-key');
        if (typeof pk !== "undefined") {
            // set the pk to width=0 to make it work with filtering
            $(this).attr('width', '0');
            createButton(this, pk, label, title, openAction);
        }
    })
}

function openBrowseForm(pk) {
    nuSetProperty('global_search_id', pk, true);
    nuForm('6448cef8823183b', '', '', '', '2');   
}

// Add an edit and browse button
// Icon list: https://fontawesome.com/v5/search?m=free
addButtons(0, '<i class="fas fa-search-plus"></i>', 'Open Details', openBrowseForm);