calm-processor-37645
02/21/2025, 6:06 AMHTTP error! Status: ${response.status})
}
const data = await response.json()
if (Array.isArray(data.users)) {
const normalizedMobileNumber = mobileNumber.replace(/\D/g, '') // Remove non-digit characters
const user = data.users.find((user) => user.phone.replace(/\D/g, '') === normalizedMobileNumber)
if (user) {
workflow.result = {
id: user.id,
firstName: user.firstName,
lastName: user.lastName,
email: user.email,
phone: user.phone
}
console.log('User found:', workflow.result)
return user
} else {
workflow.result = null
}
}
console.log('Invalid response format or missing users array.')
return null
} catch (error) {
console.error('Error fetching user data:', error)
workflow.result = null
return null
}
}
// Example usage
getUserByMobile().then((user) => {
if (user) {
console.log('Stored user details in workflow.result:', workflow.result)
} else {
console.log('User not found.')
}
})
From the phone number user enters fetch the details of the user like first name,id etc
after fetching it would save in the variable name result it is not storing the value in workflow.result variable
i have tried by adding logs but it is not saving in the variable but in the log it is showing that value has been saved and when priting workflow.result it is showing the value
please helppwhite-nest-40686
02/21/2025, 7:19 AMwhite-nest-40686
02/21/2025, 7:41 AMwhite-nest-40686
02/21/2025, 7:42 AMts
async function getUserByMobile(mobileNumber: string): Promise<object | null> {
try {
//const mobileNumber = workflow.Phone // Fetch mobile number from workflow variable
if (!mobileNumber) {
console.error('Mobile number is undefined or empty.')
return null
}
const response = await axios.get('https://dummyjson.com/users?limit=10') // Replace with actual API URL
if (!response.data) {
// throw new Error(`HTTP error! Status: ${response.status}`)
console.error(`HTTP error! Status: ${response.status}`)
return null
}
const users = response.data.users
if (Array.isArray(users)) {
const normalizedMobileNumber = mobileNumber.replace(/\D/g, '') // Remove non-digit characters
console.log('normalizedMobileNumber', normalizedMobileNumber)
const user = users.find((user) => user.phone.replace(/\D/g, '') === normalizedMobileNumber)
if (user) {
console.log('User found:', user)
return user
} else {
console.log('User NOT found:')
}
}
//console.log('Invalid response format or missing users array.')
} catch (error) {
console.error('Error fetching user data:', error)
}
return null
}
// Example usage
getUserByMobile('+61 260-824-4986').then((user) => {
if (user) {
workflow.result = {
id: user.id,
firstName: user.firstName,
lastName: user.lastName,
email: user.email,
phone: user.phone
}
console.log('Stored user details in workflow.result:', workflow.result)
} else {
console.log('User not found.')
}
})calm-processor-37645
02/21/2025, 9:13 AMcalm-processor-37645
02/21/2025, 9:22 AMwhite-nest-40686
02/21/2025, 1:53 PMworkflow.result is set in .then()
try this js
const user = await getUserByMobile('+61 260-824-4986')
if (user) {
workflow.result = {
id: user.id,
firstName: user.firstName,
lastName: user.lastName,
email: user.email,
phone: user.phone
}
console.log('1. Stored user details in workflow.result:', workflow.result)
} else {
console.log('User not found.')
}