Retrieving a param from nav

Hello all,

Is there a way to pass in a param from a view in nav? What I want to do is to be able to pass in a ticket param from Ticket/edit_ticket to nav so that I can access its name and its project’s name so I can do this:

image

I’m using TypeScript so I’m not sure if I can import view from an xml file

This works, but I’m not sure if this is best practice

function getProjectName() {
    let edit_view = journey.viewStack.find('Ticket/edit_ticket');
    if (edit_view && edit_view.variables) {
        let ticket = edit_view.variables.ticket;
        console.log("Ticket: " + ticket.id);    
        return ticket.project();
    } else {
        return '';
    }
}

Thanks,

Alex

Hi @alex.dang

Unfortunately the nav view is somewhat independent of the other views and so you cannot pass vars to it.

Yours is a reasonable solution, basically based on the fact that it works :smiley: That said, since you can potentially have more than one ‘Ticket/edit_ticket’ view on your viewStack, unless you are actively managing your stack, it could cause problems.

My recommendation would therefore be to store a reference to the “current” or “active” object on the user object using a belongs_to relationship, since the user object is globally available, and then using that rel to get the object you are looking for in the nav logic.

So in your case, your function would look like this.

function getProjectName() {
    let ticket = await user.current_ticket()
    if (ticket) {
        let project = await ticket.project();
        return project ? project.name : '';
    } else {
        return '';
    }
}

You obviously just need to remember to update the reference on the user object in your workflow

Another option would be to store the reference in a Global JS var or in a LocalDB object instead of the relationship to the User object. This would make the reference Device specific, as opposed to user specific.

I hope this helps