Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

Creating Skill Record with Lookup Field via Web Resource

Posted on by 4
I have a candidate table that has a many-to-one relationship with a skill table. This is my code for creating a record in the skill table, where rd_candidate is a lookup field. Is this correct? Is it possible to create that record using a web resource?


 
  function createCandidateSkills(skillsArray) {
            let urlParams = getUrlParameters();
            let data = JSON.parse(urlParams);

            var candidateid = data.candidateData.rd_candidateid;

            skillsArray.forEach(function(skill) {
                var req = new XMLHttpRequest();
                req.open("POST", Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.1/rd_skills", true);
                req.setRequestHeader("OData-MaxVersion", "4.0");
                req.setRequestHeader("OData-Version", "4.0");
                req.setRequestHeader("Accept", "application/json");
                req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                req.onreadystatechange = function() {
                    if (this.readyState === 4) {
                        req.onreadystatechange = null;
                        if (this.status === 204) {
                            console.log("Skill created successfully");
                        } else {
                            console.error(this.statusText);
                        }
                    }
                };
                 var skillData = {
                    "rd_candidate@odata.bind": "/rd_candidates(" + candidateid + ")",
                    "rd_name": skill.skill,
                    "rd_totalmonthsused": skill.months
                };
                req.send(JSON.stringify(skillData));
            });
        }


 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans