在具有查找列的共享点列表中插入项目

时间:2019-05-06 13:55:44

标签: javascript sharepoint-online

我正在尝试在具有两个查询列的共享点列表中插入一个项目。执行下面显示的代码后,我已成功将项目插入列表,但查找列不包含任何值。我已经确定查找项目的ID在第二个列表中已经存在,并且如果我放置一个随机ID,则会出现一个异常,告诉我根本无法插入该项目。因此,该问题与id问题无关。 这是我的列表的屏幕截图:https://imagizer.imageshack.com/img921/3483/J08viH.png

我的代码:

function ajout_table_double() {
    var nom_local=document.getElementById('localField').value;
    if (idSanByOrder.length>=1) {
        for(var i = 0;i < idSanByOrder.length;i++){
            clientContext = new SP.ClientContext();
            var oList = clientContext.get_web().get_lists().getByTitle('Plat_FastFood');
            var itemCreateInfo = new SP.ListItemCreationInformation();
            this.oListItem = oList.addItem(itemCreateInfo);

            var lookupSingle = new SP.FieldLookupValue();  
            var lookupSingle2 = new SP.FieldLookupValue();  
            lookupSingle.set_lookupId(idSanByOrder[i]); // i've tried putting directly the id's value directly, but same problem occured
            lookupSingle2.set_lookupId(local_tab[0]);

            oListItem.set_item('fast_food_column', lookupSingle);  
            oListItem.set_item('plat_column', lookupSingle2);  
            oListItem.set_item('Title', 'local: '+nom_local);

            oListItem.update();

            clientContext.load(oListItem);
            clientContext.executeQueryAsync(
                Function.createDelegate(this, this.onQueryDoubleSucc), 
                Function.createDelegate(this, this.onQueryDoubleFail)
            );
        }
    }
}

1 个答案:

答案 0 :(得分:0)

脚本似乎很好,请尝试确认ID正确。

我测试过的脚本。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
    usr = (EditText) findViewById(R.id.editText);
    psw = (EditText) findViewById(R.id.editText2);
    text = (TextView) findViewById(R.id.textView8);
    login = (Button) findViewById(R.id.button3);
    login.setOnClickListener(this);
    text.setOnClickListener(this);
    FirebaseApp.initializeApp(this);
    at = FirebaseAuth.getInstance();
    fb = FirebaseDatabase.getInstance();
    ref = fb.getReference("Status");
   }


@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.textView8:
            Intent i = new Intent(this, forgotpassword.class);
            startActivity(i);
            break;

        case R.id.button3:
            if ((usr.getText().toString()).equals("") || 
    (psw.getText().toString()).equals("")) {
    Toast.makeText(this,"Enter login 
    credentials",Toast.LENGTH_LONG).show();
            } else {
                final ProgressDialog pd = ProgressDialog.show(this, 
      "Please Wait", "Processing", true);
                at.signInWithEmailAndPassword(usr.getText().toString(), 
                 psw.getText().toString()).addOnCompleteListener(new 
               OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        pd.dismiss();
                        if (task.isSuccessful()) {

                            Intent inp = new Intent(getApplicationContext(), 
                      select.class);
                            inp.putExtra("email", usr.getText().toString());
                            startActivityForResult(inp, 0);
                        } else {
                  Toast.makeText(getApplicationContext(),"Login 
                          Failure",Toast.LENGTH_LONG).show();


                        }
                    }
                });

                break;
            }
    }
}