Advertisement
Guest User

Untitled

a guest
Aug 28th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.   //get person id from querystring
  3.   var person = getQueryVariable('rid');
  4.   //clean up matrix items without related skills
  5.   var url = 'bmzta34wf?a=API_PurgeRecords&query={6.EX.}&apptoken=bh89wwc8sxc9ac2g83fme83nsi';
  6.   var promise = $.get(url);
  7.   //clean up matrix items without related people
  8.   url = 'bmzta34wf?a=API_PurgeRecords&query={31.EX.}&apptoken=bh89wwc8sxc9ac2g83fme83nsi';
  9.   promise = $.get(url);
  10.   //get all skills from Skills table
  11.   url = 'bmzizdnpr?a=API_DoQuery&clist=a&apptoken=bh89wwc8sxc9ac2g83fme83nsi';
  12.   promise = $.get(url);
  13.   $.when(promise).then(function(xml) {
  14.     //loop through skills
  15.     $(xml).find('record').each(function() {
  16.       //get skill id
  17.       var skill = $(this).find("record_id_").text();
  18.       //check for existing combination of skill and person on 'SKills List' table
  19.       var url = 'bmzta34wf?act=API_DoQueryCount&clist=a&query={6.EX.' + skill + '}AND{31.EX.' + person + '}&apptoken=bh89wwc8sxc9ac2g83fme83nsi';
  20.       var promise = $.get(url);
  21.       $.when(promise).then(function(xml) {
  22.         $(xml).find('qdbapi').each(function() {
  23.           //check if an item with the skill x person combination already exists
  24.           var matches = $(this).find('numMatches').text();
  25.           //if it does not exist, create it
  26.           if (matches == 0) {
  27.             var url = 'bmzta34wf?act=API_AddRecord&clist=a&_fid_6=' + skill + '&_fid_31=' + person + '&apptoken=bh89wwc8sxc9ac2g83fme83nsi';
  28.             var promise = $.get(url);
  29.           }
  30.         });
  31.       });
  32.     });
  33.   })
  34. })
  35. //function to get querystring values from variables
  36. function getQueryVariable(variable) {
  37.   var query = window.location.search.substring(1);
  38.   var vars = query.split('&');
  39.   for (var i = 0; i < vars.length; i++) {
  40.     var pair = vars[i].split('=');
  41.     if (pair[0] == variable) {
  42.       return pair[1];
  43.     }
  44.   }
  45.   return (false);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement