
Announcements
Hi everyone,
I have a multistep form and i need to auto populate lookup field.
This is modal and it is out of box. I implemented from power app management.
I belive that this should be doable in power pages management. I tried to write javascript code but when i click submit button, the record is saving automatically. I used this code but i couldn't handle the get record id after saving dataverse but before closing this modal. And how can i get the record id which is created in my account information step to set lookup field.
document.addEventListener('DOMContentLoaded', function() {
var button = document.getElementById('InsertButton');
var entityLogicalName = $("#EntityFormControl_EntityFormView_EntityName").val();
console.log(entityLogicalName);
// Getting the Record ID
var recodId = $("#EntityFormControl_EntityFormView_EntityID").val();
console.log(recodId);
if (button) {
button.addEventListener('click', function(event) {
// Getting the Entity Logical
var entityLogicalName = $("#EntityFormControl_EntityFormView_EntityName").val();
console.log(entityLogicalName);
// Getting the Record ID
var recodId = $("#EntityFormControl_EntityFormView_EntityID").val();
console.log(recodId);
});
} else {
console.error('Buton bulunamadı: InsertButton');
}
});
You should be able to catch the 'success' message if the record has been successfully created, the message will have the id in the JSON data. However, lookup fields have this behaviour by default if you add a metadata record for the lookup attribute: Configure basic form metadata for Power Pages | Microsoft Learn
Behind the scenes this functionality does exactly the same by the way:
window.addEventListener('message', function (e) {
var origin, message;
if (!window.location.origin) {
origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : ''); // IE does not set origin
} else {
origin = window.location.origin;
}
if (e.origin != origin) {
return;
}
try {
message = $.parseJSON(e.data);
} catch (jsonParseError) {
return;
}
if (message.type === 'Success') {
e.preventDefault();
console.log( message.id);
}
e.target.removeEventListener(e.type, arguments.callee);
});
});