How to redirect to another page when a record is selected in sn-record-picker

vinuthna16
Tera Contributor

Hi Team,

<sn-record-picker field="location" table="'sys_user'" display-field="'name'" value-field="'sys_id'" search-fields="'name'" page-size="100" ></sn-record-picker>

<div class="form-group">
<input type="submit" value="Search" class="btn btn-primary">
</div>

When I select a record  in the above search field and press submit it should redirect to another page .Please Help How can I achieve this.

Thanks

Vinuthna

2 REPLIES 2

Amitoj Wadhera
Kilo Sage

Hi @vinuthna16 ,

 

PFB,

 

 

 

<form id="searchForm" onsubmit="return handleSubmit(event)">
    <sn-record-picker
        field="location"
        table="'sys_user'"
        display-field="'name'"
        value-field="'sys_id'"
        search-fields="'name'"
        page-size="100"
        ng-model="selectedRecordId"
    ></sn-record-picker>

    <div class="form-group">
        <input type="submit" value="Search" class="btn btn-primary">
    </div>
</form>

 

 

Client Controller:

 

 

function handleSubmit(event) {
    // Prevent the default form submission behavior
    event.preventDefault();

    // Get the selected record ID from the model (or the form input)
    var selectedRecordId = document.querySelector('sn-record-picker').value;

    // Construct the URL to redirect to, including the selected record ID as a query parameter
    var redirectUrl = `/desiredPage?recordId=${selectedRecordId}`;

    // Redirect the user to the desired page
    window.location.href = redirectUrl;

    // Return false to prevent form submission (since we are manually handling the redirection)
    return false;
}

 

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Regards,

Amitoj

Community Alums
Not applicable

Hi @vinuthna16 ,

I tried your problem in my PDI and it works for me 

HTML 

<sn-record-picker field="user_name" sn-change="c.userRecord()"table="'sys_user'" ng-change="c.redirectFun()" display-fields="'email'"  display-field="'user_name'" display-fields="'user_name'" value-field="'user_name'" field="user_name" search-fields="'user_name'" page-size="100" ></sn-record-picker>

Client script 

c.redirectFun = function() {
		alert('here');
    window.location.href = 'sys_user_list.do'; // You can pass link here
	}

Result 

SarthakKashyap_0-1714552294872.png

SarthakKashyap_1-1714552310693.png

 

 Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak