Maybe other members also need this, you can try like I did.
The first step is to create a Text Custom Field, select Placement, Checklist Show custom field on printed documents, if you want to display it in Transaction View, and [Create]
Next, Edit the Custom Field, to get the Name and GUID, and modify the script according to the Name and Guid in your Custom Field.
Copy/paste Edited Script to Description field and [Update]
hello guys,
kindly help me this scrip - I tried to do it myself but it did not work for me. I canβt see the user name who created the transaction. I strictly followed the instructions of @Mabaega.
Since this uses the same trick, Iβm posting a code example here. As a warning, you have to know what you are doing if you use something outside the system recommendations.
Its not perfect, it just work for reference.
Change the Access Token/apikey, and FieldGuid with Text Custom Field UUID according to the Text Custom Field you are using.
<script>
document.addEventListener('DOMContentLoaded', () => {
const FieldGuid = "8ccdffdb-7181-4bd4-966e-782732904be2";
const apiKey = 'Cg5NYWlsamV0X1RoZW1lcxISCR1IANtvy3hOEZ2Icxvn5PoUGhIJw4GdNlGfBkQRqX1zeOUZesU=';
function updateCustomField(value) {
if (typeof app !== 'undefined' && app.CustomFields2 && app.CustomFields2.Strings) {
app.CustomFields2.Strings[FieldGuid] = value;
app.$forceUpdate();
}
}
function handleCustomerNameChange(newName) {
updateCustomField(null);
if (newName && newName.trim() !== '') {
const baseUrl = window.location.origin;
const apiUrl = `${baseUrl}/api2/customers?term=${encodeURIComponent(newName)}&fields=AccountsReceivable`;
fetch(apiUrl, {
headers: {
'accept': 'application/json',
'X-API-KEY': apiKey
}
})
.then(response => {
if (!response.ok) {
throw new Error('Failed to fetch data from the API.');
}
return response.json();
})
.then(apiData => {
if (apiData.customers && apiData.customers.length > 0) {
const customer = apiData.customers[0];
const accountsReceivable = customer.accountsReceivable;
if (accountsReceivable) {
const value = accountsReceivable.value;
const currencyCode = accountsReceivable.currency;
const formattedValue = formatCurrency(value, currencyCode);
if (value !== null && value !== 0) {
updateCustomField(formattedValue);
}
}
}
})
.catch(error => {
console.error('Error fetching or parsing API data:', error.message);
});
}
}
function formatCurrency(value, currencyCode) {
if (currencyCode) {
const formatter = new Intl.NumberFormat(undefined, {
style: 'currency',
currency: currencyCode,
minimumFractionDigits: 2,
maximumFractionDigits: 2
});
return formatter.format(value);
} else {
const formatter = new Intl.NumberFormat(undefined, {
style: 'decimal',
minimumFractionDigits: 2,
maximumFractionDigits: 2
});
return formatter.format(value);
}
}
const createButton = document.querySelector('button.btn.btn-primary[onclick="ajaxPost(true)"]');
if (createButton) {
const customerElement = document.getElementById('select2-chosen-2');
if (customerElement) {
handleCustomerNameChange(customerElement.textContent.trim());
};
const observer = new MutationObserver(mutationsList => {
for (let mutation of mutationsList) {
if (mutation.type === 'childList') {
const newTextContent = mutation.target.textContent.trim();
handleCustomerNameChange(newTextContent);
}
}
});
const config = { childList: true, subtree: true };
observer.observe(customerElement, config);
}
});
</script>
@eko, i was unable to past the script here, rather I uploaded a pdf.
Moreover, I am not a professional programmer; merely i copied @Mabaega script and only included this line: let createdBy = βDEFAULT_NAMEβ; to the old script and nothing works.
Respect.
Please PDF files are not allowed. It is easy to paste the code. Just select all the code you used and paste it in the post. mark it all and click on </> button above.
The script works fine on Desktop and Server (I do not have Cloud) so it is essential to show the code you used and also screenshots about what you did and where do you think it goes wrong. This has nothing to do with being a professional programmer or not. For those that try to assist you it is essential that you provide all the essential information so that it can be analyzed and resolved.