Populate Fields when Clicking “Save” on Custom List

I have a SP 2013 Custom List with 2 automatically generated numbers. Currently, they are queried and populated upon selection of input values for the first 2 fields. The form works great for a single user, but I’d like to accommodate simultaneous users if possible. As is, having simultaneous users can create duplicate tracking numbers.

I tried running the queries and populating the 2 fields which are each a portion of the tracking number (calculated field) within the PreSaveAction function, which does populate the fields on the new item form, however, the values do not get saved within the list item on the AllItems page.

Any ideas on a way to make this work? Here’s my code:

// Query item ID for most recent item with the selected associated tracking number var collListItems; function QueryExistingLastID() {     var rvID = $  ("input:text[title='Associated Tracking Number']").val();     var clientContext = new SP.ClientContext();     var TrackerList = clientContext.get_web().get_lists().getByTitle('Tracker');     var query = new SP.CamlQuery();     query.set_viewXml("<View><RowLimit>1</RowLimit><Query><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy><Where><Eq><FieldRef Name='Status'/><Value Type='Text'>" + rvID + "</Value></Eq></Where></Query></View>");     collListItems = TrackerList.getItems(query);     clientContext.load(collListItems);     clientContext.executeQueryAsync(Function.createDelegate(this, this.ExistingQuerySucceed), Function.createDelegate(this, this.ExistingQueryFailed)); }  // Populate subject number by adding 1 to the previous subject number for the selected associated tracking number function ExistingQuerySucceed(sender, args) {     var listItemEnumerator = collListItems.getEnumerator();     while (listItemEnumerator.moveNext()) {         var oListItem = listItemEnumerator.get_current();            }     if ($  ("select[id^='Status']").val() == "Existing")     {     $  ("input[id^='Subject_x0020_Num']").val(oListItem.get_item("Subject_x0020_Num")+1);     } }  function ExistingQueryFailed(sender, args) {     // Alert error message if list item above fails to load     alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace()); }  // Query last list item where Status = "New" var collListItem; function QueryLastNewItem() {     var clientContext = new SP.ClientContext();     var TrackerList = clientContext.get_web().get_lists().getByTitle('Tracker');     var query = new SP.CamlQuery();     query.set_viewXml("<View><RowLimit>1</RowLimit><Query><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy><Where><Eq><FieldRef Name='Status' /><Value Type='Text'>New</Value></Eq></Where></Query></View>");     collListItem = TrackerList.getItems(query);     clientContext.load(collListItem);     clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));         }  // Populate new tracking number by adding 1 to the most recent tracking number function onQuerySucceeded(sender, args) {     var listItemEnumerator = collListItem.getEnumerator();     while (listItemEnumerator.moveNext()) {         var oListItem = listItemEnumerator.get_current();            }     if ($  ("select[id^='Status']").val() == "New")         {         $  ("input[id^='Tracking_x0020_Numbe']").val(oListItem.get_item('Tracking_x0020_Numbe')+1);         } }   function onQueryFailed(sender, args) {     // Alert error message if list item above fails to load     alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace()); }  // Validate that an appropriate Associated Tracking Number has been selected if the first field says existing function PreSaveAction() {     var q = document.getElementById('Status$  DropDownChoice');     var question = q.options[q.selectedIndex].text;      var rvtracking = $  ("input:text[title='Associated Tracking Number']").val();     var re_rvtracking = /^RVFUF[0-9]{2,2}-[0-9]{4,4}$  /;      if((!re_rvtracking.test(rvtracking)) && question == "Existing")     {     $  (".ms-metadata:contains('You must search and select the associated tracking number from the drop down options.')").css("color", "FireBrick");     return false;     }      else     {     $  (".ms-metadata:contains('You must search and select the associated tracking number from the drop down options.')").css("color", "DimGray");     // Run the queries and populate the fields as indicated above     QueryLastNewItem();     QueryExistingLastID();     return true;     } } 

Populate de un array de IDs anidada en mongoose

Tengo el modelos de los usuarios y el modelos de los post. En el modelo de los post, cuando un usuario hace like a un post, hago referencia a la id de ese usuario.

En el modelo de los user hago lo mismo, cuando el user da like a un post, añado la id del post al que le ha dado like.

Cuando se cargan los posts, necesito obtener la data de los usuarios que han dado like a ese post y he hecho lo siguiente:

Modelo user:

const userSchema = new Schema({  name: {     type: String,     required: [ true, 'El nombre es necesario' ] }, avatar: {     type: String,     default: `av-1.png` }, email: {     type: String,     unique: true,     required: [ true, 'El email es necesario' ] }, password: {     type: String,     required: [ true, 'La contraseña es necesaria' ] }, likes: [{     type: Schema.Types.ObjectId,//String      ref: 'Post' }]}); 

Modelo post:

const postSchema = new Schema({   created: {     type: Date }, message: {     type: String }, imgs: [{     type: String }], coords: {     type: String }, user: {     type: Schema.Types.ObjectId,     ref: 'User',     required: [ true, 'Debe existir una relación con un usuario' ] }, info: {     likes: {         number: {             type: Number         },         usersId: [{             type: Schema.Types.ObjectId,             ref: 'User'         }]     } }    }); 

Obtención de los post con los usuarios que han dado like populados:

const posts = await Post.find()                         .sort({_id: -1})                 // Orden descendente                         .skip( skip )                         .limit(10)                       // Maximo 10 por petición                         .populate('user', '-password')                         .populate( {                              path: 'metrics',                             populate: {                                 path: 'likes',                                 populate: {                                     path: 'userId',                                   }                                }                            } )  // Obtener datos user -pass                         .exec();   res.json({     ok: true,     page,     posts }); 

Error: (node:8216) UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value “{ usersId: [] }” at path “_id” for model “Post”

¿Como puedo hacer para obtener la data de todos los usuarios que hay en el array userId?

Magento 2 – How to use dynamic row system to populate form in custom shipping module

I built a Magento 2 custom module for shipping that has a select drop down field for users to choose an option. I want to be able to set those options in the admin for the module using the dynamic row system. I have the form built and working. This is the section for the select box using:


<item name="checkout_building_address" xsi:type="array">         <item name="component" xsi:type="string">Magento_Ui/js/form/element/select</item>         <item name="config" xsi:type="array">             <item name="customScope" xsi:type="string">customCheckoutForm</item>             <item name="template" xsi:type="string">ui/form/field</item>             <item name="elementTmpl" xsi:type="string">ui/form/element/select</item>         </item>         <item name="options" xsi:type="array">             <item name="0" xsi:type="array">                 <item name="label" xsi:type="string">Please select value</item>                 <item name="value" xsi:type="string"></item>             </item>             <item name="1" xsi:type="array">                 <item name="label" xsi:type="string">Option 1</item>                 <item name="value" xsi:type="string">value_1</item>             </item>             <item name="2" xsi:type="array">                 <item name="label" xsi:type="string">Option 2</item>                 <item name="value" xsi:type="string">value_2</item>             </item>         </item>         <item name="value" xsi:type="string">Please Select Value</item>         <item name="provider" xsi:type="string">checkoutProvider</item>         <item name="dataScope" xsi:type="string">customCheckoutForm.checkout_building_address</item>         <item name="label" xsi:type="string">Select Building Address</item>         <item name="sortOrder" xsi:type="string">2</item>     </item> 

I also followed the Mage docs for getting the dynamic rows in the admin. That is working fine and saves the information to the core_config_data table as a serialized array.

{"_1564590939871_871":{"addresses":"123 Amy Street Any Town, CA 92234"},"_1564593462830_830":{"addresses":"1475 Main St. Any Town, CA 90210"}} 

I cannot figure out how to get that data to populate the select box in my form.

Thanks in advance for the help!

* UPDATE * I am now using this in Helper>Data.php

public function getJsonConfigValue($  configPath, $  store = null)     {         $  value = $  this->getJsonConfigValue($  configPath, $  store);          if (empty($  value)) return false;          if ($  this->isSerialized($  value)) {             $  unserializer = ObjectManager::getInstance()->get(\Magento\Framework\Unserialize\Unserialize::class);         } else {             $  unserializer = ObjectManager::getInstance()->get(\Magento\Framework\Serialize\Serializer\Json::class);         }          return $  unserializer->unserialize($  value);     } 

and I can see that data in a template using:

public function getJsonSerialized()     {            $  arrayItems = $  this->helper->getJsonConfigValue('carriers/dynamic/addresses/address_list');          return json_encode($  arrayItems);     } 

And this in a template file view>frontend>templates>array.phtml

<?php echo $  block->getJsonSerialized(); ?> 

And it appears like this on the page:

{"_1564763325005_5":{"addresses":"123 My Street, Bldg. 1, My Town, IA 00351"}} 

How do I turn it into something that I can use in a form I built in a custom module to populate the select drop down field?

It this my problem? – return json_encode($ arrayItems);

I can’t find what I think I am looking for.


Populate field onLoad Social feed SharePoint 2013

I am try to auto populate user e-mail,name,title on a sharepoint form. I can see the values when I inspect the page (F12) but they dont appear on the form onload. i obtain the input fields id via the developer tool, not 100% sure I am using the correct ID.

here is the code I am using:

$  (function () { getUserProfileInfo(); 


function getUserProfileInfo() {

var fullUrl = "https://sites/sites/dome/_api/social.feed/my";  $  .ajax({     url: fullUrl,     type: "GET",     headers: {         "accept": "application/json;odata=verbose",         "content-type": "application/json;odata=verbose",     },     success: onUserInfoQuerySucceeded,     error: onQueryFailed }); 


function onUserInfoQuerySucceeded(data) { var userInfoItemE = data.d.Me.EmailAddress; var userInfoItemN = data.d.Me.Name; var userInfoItemT = data.d.Me.Title;

document.getElementById('Email_a6570af6-8b72-4ab0-814d-93f50f26e185_$  TextField').innerHTML = userInfoItemE; document.getElementById('Name_b6023c0f-43be-45b4-b946-22ac2933bb77_$  TextField').innerHTML = userInfoItemN; document.getElementById('Title_fa564e0f-0c70-4ab9-b863-0177e6ddd247_$  TextField').innerHTML = userInfoItemT; 

} function onQueryFailed(sender, args) { alert(“Error”); }

Why would you populate a temp table for reporting?

I’m maintaining a legacy accounting application that runs nearly all of its reports by populating a temp table at runtime. The temp table is dropped on a daily basis and includes information about the report’s configuration (i.e. which terminal ran it, landscape vs. portrait etc…). Is there a reason to have the application do this rather than select the configuration view in real time and pull the data it needs from a custom view?

Can a workflow populate values in a lookup field for all the items in the list?

I have a list called Contacts, with 4000+ entries. It currently has a dropdown choice column with four specified values for different offices (MAO, NHO, MEO and CTO). I want to convert this dropdown choice column to a lookup column that links to a newly created list with the four offices in it. The reason for this is because I want to use Mark Rackley’s cascade dropdowns to filter Contacts by office.

From what I understand you can’t directly convert a Choice field to a lookup field. So I thought I’d just create a new lookup field that links to the new list with the offices. The problem is there are already 4000+ items in this list that would need to have the applicable office chosen in this new lookup field.

Is there a way to create a workflow that will look at the value in the choice field and then select the matching value in the new lookup field for all the contacts? For example, it sees MAO in the choice field and then selects MAO under the new lookup field.

how to populate a list column with the Site Title

So I have a list in a site template that needs to contain certain information about the site automatically. I need a way to fill the Title column of the list with the Site Title and the Project Owner column with column with the content of the Owners permission group.

Is there a way to either auto populate these fields on site creation or perform this action with a workflow?