Untitled

 avatar
unknown
typescript
2 years ago
1.0 kB
1
Indexable

		async function setTeaUser(){
			let teaUserId = formContext.getAttribute("nrq_teauserid").getValue();
			let ownerRef = formContext.getAttribute("ownerid").getValue();	
			if(ownerRef && !teaUserId) {
				try{
					let retrievedTeaUser = await getMatchedTeaUsers(ownerRef[0].id);
					let lookupValue: Xrm.EntityReference<"nrq_teauser">[] = [{id: retrievedTeaUser.nrq_teauserid, entityType: "nrq_teauser", name: retrievedTeaUser.nrq_name}];
					formContext.getAttribute("nrq_teauserid").setValue(lookupValue);
				}catch(err){
					Xrm.Navigation.openAlertDialog({
						text: 'No tea user found'
					})
				}		
			}
		}
		
		async function getMatchedTeaUsers(ownerId: string){
			return await XrmQuery.retrieveMultiple(x => x.nrq_teausers).select(x => [x.createdon, x.nrq_name])
			.andFilter(x => Filter.equals(x.nrq_crmuserid_guid, Filter.makeGuid(ownerId)))
			.andFilter(x => Filter.equals(x.statecode, nrq_teauser_statecode.Active))
			.top(1).orderDesc(x => x.createdon).promiseFirst();
		}
Editor is loading...